[VB] CloseWindowByCaption
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Const WM_CLOSE = &H10
Const WM_DESTROY = &H2
Public sub CloseWindowByCaption(Caption As String)
dim hParent as long
hParent = FindWindow(vbNullString, Caption)
If hParent <> 0 Then 'close it
PostMessage hParent, WM_CLOSE, 0, 0
PostMessage hParent, WM_DESTROY, 0, 0
End If
End sub