By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

Excel Application.Quit doesn't

P: n/a
This should be a fairly common scenario, but I haven't yet found a solution
on google.

(On WinXP Pro SP2 / Access 2003 / Excel 2003)
The following code, when run from Access, leaves a copy of Excel.exe hanging
around.

'***********************************************
Sub testXL()

Dim objXL As Object
Dim wkbXL As Object
Dim strFileName As String

On Error GoTo errHandler
strFileName = "C:\Test.xls"
Set objXL = CreateObject("Excel.Application")
Set wkbXL = objXL.Workbooks.Open(strFileName)

exitHere:
On Error Resume Next
wkbXL.saved = True
wkbXL.Close

' also tried this
' wkbXL.Close savechanges:=False

Set wkbXL = Nothing
objXL.Quit
Set objXL = Nothing
On Error GoTo 0
Exit Sub

errHandler:
MsgBox (Err.Description)
Resume exitHere

End Sub
'***********************************************

Early binding seems to make no difference. Any ideas on how to release Excel
from memory would be appreciated.



Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Chuck Grimsby" <c.*******@worldnet.att.net.invalid> wrote in message
news:61********************************@4ax.com...

Generally, I do something like (using late binding):

Dim objExcel As Object
Set objExcel = CreateObject("excel.application")
objExcel.Workbooks.Open strFileName

<do whatever>

' Note: make sure you use .Save on every ActiveWorkbook
' that changes
objExcel.ActiveWorkbook.Save

objExcel.Application.Quit
Set objExcel = Nothing

Other then the ActiveWorkbook.Save statement, not too much difference
then the code you are using, however you might want to toss in a
"objExcel.Visible = True" statement to see what Excel is doing on the
screen. Occasionally, you can catch more then a few errors and
warnings which pop up that you'll have to deal with (Circular
references, macro warnings, etc.).


Hi Chuck, thanks for the reply. No luck with your code - I tried several
variations along the lines of ActiveWorkbook.Save and I'm still seeing the
pesky thing in memory. I also tried making objXL visible but nothing showed
up - it just hides itself after the Quit statement. I thought that there may
have been a dialog asking for user input (whether to run macros or some
such) but nothing like that.

I wonder if this is something to do with Excel 2003. I'll load an earlier
version onto another machine and try that.
Nov 13 '05 #2

P: n/a
Try it this way:

(Tools/References/Microsoft Excel Object Library)

Dim objExcel As Excel.Application, ...

Set objExcel = CreateObject("Excel.Application")
...
objExcel.Quit

I have also experimented with

Dim objExcel As New Excel.Application

which eliminates the Set objExcel statement, but did not have much
consistent luck with that. I have had consistent luck with Dim objExcel
As Excel.Application --- Set objExcel =
CreateObject("Excel.Application"), and GetObject also.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

P: n/a
"Rich P" <rp*****@aol.com> wrote in message
news:41**********************@news.newsgroups.ws.. .
Try it this way:

(Tools/References/Microsoft Excel Object Library)

Dim objExcel As Excel.Application, ...

Set objExcel = CreateObject("Excel.Application")
..
objExcel.Quit

I have also experimented with

Dim objExcel As New Excel.Application

which eliminates the Set objExcel statement, but did not have much
consistent luck with that. I have had consistent luck with Dim objExcel
As Excel.Application --- Set objExcel =
CreateObject("Excel.Application"), and GetObject also.


Hi Rich. Same deal. I tried early binding, late binding, every which way.
I'm running out of ideas.

Wehn I get a chance I'll load up Excel 97 or 2K and see if the problem is
specific to Excel 2003.
Nov 13 '05 #4

P: n/a
"Chuck Grimsby" <c.*******@worldnet.att.net.invalid> wrote in message
news:hc********************************@4ax.com...
Generally, I do something like (using late binding):

Dim objExcel As Object
Set objExcel = CreateObject("excel.application")
objExcel.Workbooks.Open strFileName

<do whatever>

' Note: make sure you use .Save on every ActiveWorkbook
' that changes
objExcel.ActiveWorkbook.Save

objExcel.Application.Quit
Set objExcel = Nothing


No, still no difference. But I've found that this behaviour only occurs with
Excel 2003; not 2002 or 2000. Perhaps some new feature of Excel 2003 is not
letting the program quit. I've reproduced this on two different machines
here, both running Office 2003.

I think this might qualify as a bug. In the meantime I'm going to just have
to use brute force to close it.
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.