Closing Excel via Access VBA

  • Thread starter Thread starter ChrisBat
  • Start date Start date
C

ChrisBat

Hi,

I posted a question last week, got a response, tried it,
it doesn't work.
What I'm trying to do in brief is click a button on an
access form, open Excel, download a report from my
intranet, manipulate and clean the data, open my report
template (also in Excel), transfer the data, and then save
the new report. I then need to close Excel and return to
the form. The problem that I am having is that I cannot,
despite all my best efforts, get the process excel.exe to
close. The beginning and the end of my code reads as
follows:
Dim ex as New Excel.Application
Dim wrkbk as Excel.Workbook
Dim xlApp as Excel.Application
Set xlApp = Excel.Application
Set wrkbk = ex.Workbooks.Add

I then go on with my code, ending with:

ex.Quit
wrkbk.Quit
xlApp.Quit
Set ex = Nothing
Set wrkbk = Nothing
Set xlApp = Nothing

Although this seems to me to be the format followed by the
MSDN, as I said above, excel.exe just will not close.
Does anybody *please* have any suggestions???
Thank you soooo much in advance...
Chris
 
I got this from Brian Reich. It may help you. Good luck.

Here's a little code snippet I tested with:

Dim o As Object
Set o = CreateObject("Excel.Application")
MsgBox o
MsgBox "Test Me"
o.Quit
Set o = Nothing

when the "test me" msgbox is open, you can launch task
manager and see Excel.exe running. Then, once you hit ok
and the code completes, you will see in task manager that
the excel instance has dissapeared.
What you were probably doing before was launching a new
Excel process (this won't show up in the Applications
section of the task manager because you launched it through
another process without a main window, but it does show
up in the processes section as you discovered), and then
closing Access without quiting the excel process. Since the
Excel.exe instance is its own process and not a child
object of the Access process, it remained alive even after
you closed Access.
 
That's actually the code that i got last week - I may not
be setting it properly, because it will close excel, but
the excel.exe process will still show up on the Task
Manager > Processes tab....any other suggestions?
 
Back
Top