I am using Access 2003 to automate an Excel workbook, but after the
code completes Excel does not quit (at least it is still listed in
Task Manager --> Processes.)
I have set a reference to the Excel 11.0 object library. I have
declared my Excel variables as...
Dim appExcel
Set appExcel = CreateObject("Excel.application")
.. opened the file...
appExcel.Workbooks.Open ("c:\PhysicianUpdates\" & qdf.Name & ".xls")
.. and clean up when done...
ActiveWorkbook.Save
appExcel.ActiveWorkbook.Saved = True
appExcel.Quit
Set appExcel = Nothing
Set rst = Nothing
Set qdf = Nothing
Set db = Nothing
Any ideas why Excel will not truly quit? Any help you can lend would
be appreciated.
Henry
You are using unqualified references to Excel objects.
ActiveWorkbook.Save needs to be
appExcel.ActiveWorkbook.Save
I'm more in favour of using a separate worbkook object
dim wr as object ' or Excel.Workbook
set wr = appExcel.Workbooks.Open("c:\PhysicianUpdates\" & qdf.Name &
".xls")
' do important stuff
wr.save
DoEvents
set wr = nothing
appExcel.Quit
set appExcel = nothing
BTW - you say you have set reference, but you declare your appExcel
as variant - for early binding
dim appExcel as Excel.Application
--
Roy-Vidar
Thanks, Roy. Unfortunately, it wasn't successful. The code is hooked
to the click event of a control on a form. If I close the database,
the Excel process ends. If the code were put into an independent
module instead on the click event of a control, might that solve the
problem?
Henry
If this wasn't successfull, then I think it is possible that you use
more unqualified referencing in the rest of your code, that needs to
be amended. But to be of assistance, we would need a bit more than
"Unfortunately, it wasn't successfull".
I don't think there would be any difference whether this resides in
a separate module vs within a forms module, the code needs to be
without any implicit referencing of Excel objects, properties and
methods.
Here's one Microsoft KB article with some information on what I think
is the problem
http://support.microsoft.com/default.aspx?kbid=178510
--
Roy-Vidar
Many thanks for the help. I qualified my range and cell objects and
now everything works like a charm.
Henry