Excel Instance Hanging Around

P

patstix

Why does this code keep an Excel instance hanging around? I free all
the COM objects:


Sub Test()
Set oXL = CreateObject("Excel.Application")
Set WBs = oXL.Workbooks
Set Wkbk = WBs.Add
Set Wkbk = Nothing
Set WBs = Nothing
oXL.Quit
Set oXL = Nothing
End Sub

If I remove the WBs.Add line then the instance disappears as it
should; what hidden object is created there and how do I free it?
 
J

Jim Thomlinson

When I run that exact code in VBA it creates and ends the new instance of
XL... I assume that is not your experience. To that end this is just a shot
in the dark. You create a workbook but you don't close the book prior to
deleting your object reference to the book. Perhaps add a close somehitn like
this...

Sub Test()
Set oXL = CreateObject("Excel.Application")
Set WBs = oXL.Workbooks
Set Wkbk = WBs.Add
Wkbk.Close Save:=False 'or something like this
Set Wkbk = Nothing
Set WBs = Nothing
oXL.Quit
Set oXL = Nothing
End Sub
 

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