Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_SYSCOMMAND As Integer = &H112
Const SC_CLOSE As Integer = &HF060
Sub CloseExcel()
Dim i As Long
i = FindWindow("xlmain", vbNullString)
SendMessage i, WM_SYSCOMMAND, SC_CLOSE, 0
End Sub