View Single Post
  #6   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

Did you do "exactly" what I suggested? Did you remove all references to Excel.Application apart from the one used to define
appExcel? Are there any other code lines that refer to Excel objects that are not fully qualified by object variables?

There are a number of traps in this area so, if you can't get your code to work, please post a complete code example that exhibits
the problem.

--

John Green - Excel MVP
Sydney
Australia


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

Thank you for your reply. I did what you suggested but I
am sitll having the same problem. The procedure ran all
the way through and finished, but Excel is still running
in tsk mgr and I get the ghost window when I try to view
the report.xls. ??? :o(

Any other suggestions?

-----Original Message-----
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.



.