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
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