G
Guest
Hi folks,
I found the following code from the web. I pase it in Access xp module.
When I ran, it gave me error message. I tried to use it for closing Excel
which had error message pop up. Could anyone help me to fix the code?
Thanks in advance.
' Closing another Application
' *************************************************************
' ***************** The command button would look like this:
Private Sub Command1_Click()
Close_External_Application "Microsoft Word"
End Sub
' *********************************************************
'compat:vb3,vb4-16
'Close_External_Application
' Description:To have a program programmatically close anoth
' er program, use this code
' By: VB Pro'
' Inputs:strCaptionTitle--caption title of window to close
' Returns:true on success, else false
' Assumes:None
' Side Effects:None'
' Close an existing program
' *********************************************************
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
I found the following code from the web. I pase it in Access xp module.
When I ran, it gave me error message. I tried to use it for closing Excel
which had error message pop up. Could anyone help me to fix the code?
Thanks in advance.
' Closing another Application
' *************************************************************
' ***************** The command button would look like this:
Private Sub Command1_Click()
Close_External_Application "Microsoft Word"
End Sub
' *********************************************************
'compat:vb3,vb4-16
'Close_External_Application
' Description:To have a program programmatically close anoth
' er program, use this code
' By: VB Pro'
' Inputs:strCaptionTitle--caption title of window to close
' Returns:true on success, else false
' Assumes:None
' Side Effects:None'
' Close an existing program
' *********************************************************
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