SweetingA
asked on
Close PDF Application - Access VBA
I have opened a pdf application in access vba to create a file but i am having problems closing it in vba. The code used to open it is detailed below.
ShellExecuteA Application.hWndAccessApp, "open", sOutFile, vbNullstring, vbNullstring, 1
All idea's welcome - file or application can be closed (prefer application)
ShellExecuteA Application.hWndAccessApp,
All idea's welcome - file or application can be closed (prefer application)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
when u use shellexecute it returns you the processid, you can then send a message telling it to close it
Call PostMessage(lRv, &H10, 0, 0)
where lRv is the return value from shellexecute
you need to add the following api dec in your module though
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
Alternatively you could use FindWindow
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
find your window, again returns lRv and use that to close it
Dim lHwnd As Long
lHwnd = FindWindow(vbNullString, sTitle)
If lHwnd = 0 Then
MsgBox "Error finding target window handle"
Exit Sub
End If
PostMessage lHwnd, &H10, 0, 0
Call PostMessage(lRv, &H10, 0, 0)
where lRv is the return value from shellexecute
you need to add the following api dec in your module though
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
Alternatively you could use FindWindow
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
find your window, again returns lRv and use that to close it
Dim lHwnd As Long
lHwnd = FindWindow(vbNullString, sTitle)
If lHwnd = 0 Then
MsgBox "Error finding target window handle"
Exit Sub
End If
PostMessage lHwnd, &H10, 0, 0
Glad I could help..
;-)
Jeff
;-)
Jeff
http://bytes.com/topic/access/answers/521068-closing-pdf-file-vba