Closing Excel via Access VBA

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
 
J

Jim/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.
 
C

ChrisBat

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top