Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 152
Default xlApp.Quit - Doesn't Close Instance.... Any ideas?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel instance won't quit [email protected] Excel Discussion (Misc queries) 0 September 6th 06 06:57 PM
Instance still there in task manager after xlapp.Application.Quit Mo[_8_] Excel Programming 4 October 27th 05 04:36 PM
unable to close macro using auto_close or application.quit gloria Excel Programming 1 January 14th 04 07:50 AM
Close Open Woorkbook and Quit Excel Lucy[_2_] Excel Programming 5 December 24th 03 02:52 PM
Close second instance of excel Neil[_11_] Excel Programming 2 December 22nd 03 03:39 AM


All times are GMT +1. The time now is 09:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"