1,488
社区成员
发帖
与我相关
我的任务
分享Private Sub Command1_Click()
Dim xlApp As Object
Set xlApp = GetObject(, "Excel.Application") '取得当前EXCEL实例
xlApp.Quit '退出
Set xlApp = Nothing '释放xlApp对象
End Sub
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, ByVal lParam As Long) As Long
Private Const WM_CLOSE = &H10
Public Function ExitProgram(ByVal strCaption As String) As Boolean '根据窗体的标题关闭窗口
Dim winHwnd As Long
Dim RetVal As Long
ExitProgram = True
winHwnd = FindWindow(vbNullString, strCaption)
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
ExitProgram = False
End If
Else
ExitProgram = False
End If
End Function