This function will try and close Excel when stepping through your code in break mode. If called fro another procedure, then it seems to work fine. Is actually for Access.
<pre>Private Const WM_CLOSE = &H10
Private Declare Function apiPostMessage _
Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) _
As Long
Private Declare Function apiFindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
Private Declare Function apiIsWindow _
Lib "user32" Alias "IsWindow" _
(ByVal hwnd As Long) _
As Long
Function fCloseVBEWindow() As Boolean
Const VBE_CLASS = "wndclass_desked_gsk"
Dim hwnd As Long
hwnd = apiFindWindow(VBE_CLASS, Application.VBE.MainWindow.Caption)
If hwnd Then
Call apiPostMessage(hwnd, WM_CLOSE, 0, 0&)
fCloseVBEWindow = (apiIsWindow(hwnd) <> 0)
End If
Application.SendKeys "~"
End Function
Sub CloseItUsage()
If fCloseVBEWindow Then
MsgBox "VBE closed"
Else
MsgBox "Failed to clode VBE"
End If
End Sub
</pre>
tom