View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
John Green[_3_] John Green[_3_] is offline
external usenet poster
 
Posts: 49
Default Can't get Excel to quit

Tod,

You are not assigning Excel to appExcel. It remains undefined. Use something like:

Dim appExcel As Excel.Application
Dim wkbWorkBook As Excel.Workbook
Dim wksWorkSheet As Excel.Worksheet

Set appExcel = New Excel.Application

'Opens a saved report
Set wkbWorkBook = appExcel.Workbooks.Open(strImpPath & txtClientName.Value & "_report.xls")

'Defines the worksheet
Set wksWorkSheet = wkbWorkBook.Worksheets("report")

You should then be able to appExcel.Quit after closing the workbook.
--

John Green - Excel MVP
Sydney
Australia


"Todd Waldron" wrote in message ...
Hi all,

I am using automation (From Access) to format a saved .xls
file. Even after all the research I have done on this
newsgroup, I still can't get Excel to quit through code.
I'm sure I must be missing something.

Below is what I'm doing in Code from Access:

*****Start*****
Dim appExcel As Excel.Application
Dim wkbWorkBook As Excel.Workbook
Dim wksWorkSheet As Excel.Worksheet

'Opens a saved report
Set wkbWorkBook = Excel.Application.Workbooks.Open
(strImpPath & txtClientName.Value & "_report.xls")

'Defines the worksheet
Set wksWorkSheet = Excel.Application.Worksheets("report")

'Run formatting code here

'Save, Close, Quit
wkbWorkBook.Save
wkbWorkBook.Close
*ATTEMPTING TO QUIT HERE*
Set appExcel = Nothing
Set wkbWorkBook = Nothing
Set wksWorkSheet = Nothing
*****End*****

If I use the variable - "appExcel.Quit", I get "RT-Err 91
ObjVar or With Block not set".

If I specify "Excel.Application.Quit", the procedure
completes successfully. However, Excel is still running
in the tsk mgr and if I try to view the report.xls I get
some kind of ghost window where I can see the Excel tool
bar (like the app is running) but no workbook.

If I comment out the ".Quit" line altogether: the
procedure completes successfully, Excel is still running
in tsk mgr, but this time I can open the report.xls and
see everything. However if I then close report.xls and
then try to open again immediately, I get the ghost Excel
window again. The only way to stop this is to exit my
Access app or quit Excel from the tsk mgr.

Any help with this would be greatly appreciated.

Thank you,

Todd Waldron
Austin, Tx.