View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
[email protected] kaldvelski@yahoo.co.uk is offline
external usenet poster
 
Posts: 2
Default Closing Excel from a DLL

Bob,

I thought it might have been my object variable too as I get references
to sheets and the workbook but explicitly setting them to Nothing first
didn't help.
I've been playing with it a bit more and seem to have it narrowed down
to something to do with the SaveAs method.

Dim xls As Excel.Application
If xls Is Nothing Then Set xls = CreateObject("Excel.Application")
'xls.DisplayAlerts = False

Dim wkbk As Workbook, sheet As Worksheet
Set wkbk = xls.Workbooks.Add
Set sheet = wkbk.ActiveSheet

wkbk.SaveAs "c:\temp.xls"
wkbk.Close SaveChanges:=False

Set sheet = Nothing
Set wkbk = Nothing

xls.Quit
Set xls = Nothing

If I comment out the SaveAs line then the Excel process does end but
with it in, it hangs around.

Cheers

Craig