使用findWindow: 先申明API及常量 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Const WM_CLOSE = &H10比如有一窗体标题为“microsoft excel” dim lWnd as long lwnd=FindWindow (vbnullstring,"microsoft excel") if not isnull(lWnd) then '找到该窗体,关闭之 PostMessage lWnd, WM_CLOSE, 0&, 0& end if
先申明API及常量
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CLOSE = &H10比如有一窗体标题为“microsoft excel”
dim lWnd as long
lwnd=FindWindow (vbnullstring,"microsoft excel")
if not isnull(lWnd) then '找到该窗体,关闭之
PostMessage lWnd, WM_CLOSE, 0&, 0&
end if