O
oliver
I'm trying to get code I found on the net to run - I need to open a
DOS command window (to run PDFTK)
I get a compile error: Sub or Function not defined.
I've tried putting the full path to kernel32. Do I need add some
'References' - at the moment I have vba. excel 11.0, ole automation.
office 11.0
Here are is the bit of code that won't run:
Option Explicit
Private Declare Function CloseHandle Lib "kernel32" ( _
ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" ( _
ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" ( _
ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Public Function ShellX( _
ByVal PathName As String, _
Optional ByVal WindowStyle As VbAppWinStyle = vbMinimizedFocus, _
Optional ByVal Events As Boolean = True _
) As Long
'Declarations:
Const STILL_ACTIVE = &H103&
Const PROCESS_QUERY_INFORMATION = &H400&
Dim ProcId As Long
Dim ProcHnd As Long
'Get process-handle:
ProcId = Shell(PathName, WindowStyle)
ProcHnd = OpenProcess(PROCESS_QUERY_INFORMATION, True, ProcId)
'wait for process end:
Do
If Events Then DoEvents
GetExitCodeProcess ProcHnd, ShellX
Loop While ShellX = STILL_ACTIVE
'clean up:
CloseHandle ProcHnd
End Function
Sub testdunno()
Dim x As Long
x = ShellX("pdftk a.pdf cat 1-endodd output b.pdf")
Beep ' done
End Sub
Thanks Oliver
DOS command window (to run PDFTK)
I get a compile error: Sub or Function not defined.
I've tried putting the full path to kernel32. Do I need add some
'References' - at the moment I have vba. excel 11.0, ole automation.
office 11.0
Here are is the bit of code that won't run:
Option Explicit
Private Declare Function CloseHandle Lib "kernel32" ( _
ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" ( _
ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" ( _
ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Public Function ShellX( _
ByVal PathName As String, _
Optional ByVal WindowStyle As VbAppWinStyle = vbMinimizedFocus, _
Optional ByVal Events As Boolean = True _
) As Long
'Declarations:
Const STILL_ACTIVE = &H103&
Const PROCESS_QUERY_INFORMATION = &H400&
Dim ProcId As Long
Dim ProcHnd As Long
'Get process-handle:
ProcId = Shell(PathName, WindowStyle)
ProcHnd = OpenProcess(PROCESS_QUERY_INFORMATION, True, ProcId)
'wait for process end:
Do
If Events Then DoEvents
GetExitCodeProcess ProcHnd, ShellX
Loop While ShellX = STILL_ACTIVE
'clean up:
CloseHandle ProcHnd
End Function
Sub testdunno()
Dim x As Long
x = ShellX("pdftk a.pdf cat 1-endodd output b.pdf")
Beep ' done
End Sub
Thanks Oliver