close excel

A

anonymousA

If you want to close all running instances of Excel, use code like

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long,
lParam As Any) As Long
Private Const WM_CLOSE = &H10


Private Sub CloseAllExcels()
Dim XLHwnd As Long
XLHwnd = FindWindow("XLMAIN", vbNullString)
Do Until XLHwnd = 0
SendMessage XLHwnd, WM_CLOSE, 0&, 0&
XLHwnd = FindWindow("XLMAIN", vbNullString)
Loop
End Sub
 
G

Guest

A solution out of thin air!

AND a copy of a response by another person, just a few days ago!!!!
 

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