View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone[_2_] Jim Cone[_2_] is offline
external usenet poster
 
Posts: 1,549
Default xlApp.Quit - Doesn't Close Instance.... Any ideas?

When I tried your code, It hung when trying to close the file unless I followed
the instructions I posted earlier:
"Close the Workbook and specify whether to save it or not."

The close line should read...
"xlApp2.Workbooks(i).Close SaveChanges:=False 'or True"
When I did the above, the new Excel instance closed without a problem.

Also, complications could arise, if your "S" drive is "elsewhere" or
the file is shared and in use.
--
Jim Cone
Portland, Oregon USA
(use object references when automating excel)




"MikeZz"
wrote in message
Hi Jim,
I did an even more basic test, just opening and closing an instance using
the following code.
It closed the instance as long as I didn't open and close a workbook - see
the 2 lines for opening and closing.

Sub CloseInstanceTest()

Dim xlApp2 As Excel.Application 'ADDED FOR MEMORY
Set xlApp2 = New Excel.Application 'ADDED FOR MEMORY
xlApp2.Visible = True
Dim wbCount, i

'If I don't do these lines of code, the Excel Instance closes.
'So as long as I don't open a file (which defeats the point), it works.
xlApp2.Workbooks.Open ("S:\C-0MNL0-0CB-001.xls")
wbCount = xlApp2.Workbooks.Count

For i = 1 To wbCount
xlApp2.Workbooks(i).Close
Next i
xlApp2.Quit
Set xlApp2 = Nothing
End Sub