' The command button would look like this: Private Sub Command1_Click()
Close_External_Application "Microsoft Word"
End Sub
Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal _
lpWindowName As Any) As Integer
Declare Function GetWindowTask Lib "User" (ByVal hWnd As Integer) As Integer
Declare Function PostAppMessage Lib "User" (ByVal hTask As Integer, ByVal wMsg _
As Integer, ByVal wParam As Integer, lParam As Any) As Integer
Public Const WM_QUIT = &H12
Function Close_External_Application(ByVal strCaptionTitle As String) As Boolean
Dim intWindowHandle As Integer
Dim intTaskHandle As Integer
Dim intPostReturnValue As Integer
' set defaults Close_External_Application = False
' get handle of window matching caption intWindowHandle = FindWindow(0&, strCaptionTitle)
If (intWindowHandle <> 0) Then
' window found intTaskHandle = GetWindowTask(intWindowHandle)
intPostReturnValue = PostAppMessage(intTaskHandle, WM_QUIT, 0, 0&)
' set return value Close_External_Application = True
End If
End Function