Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Jim,
I tried your adding this to the .close statement but it still didn't work. SaveChanges:=False I think it has something to do with our network. However, I did resolve the issue by using this trick I found: Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long 'Get Handle I created. HwndImport = xlApp2.hwnd 'Close Handle after Closing file, Quitting xlApp2 and setting = nothing. SendMessage HwndImport, WM_CLOSE, 0, 0 Thanks for your help, "Jim Cone" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel instance won't quit | Excel Discussion (Misc queries) | |||
Instance still there in task manager after xlapp.Application.Quit | Excel Programming | |||
unable to close macro using auto_close or application.quit | Excel Programming | |||
Close Open Woorkbook and Quit Excel | Excel Programming | |||
Close second instance of excel | Excel Programming |