Sub or Function not defined

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
 
O

oliver

It compiles for me... What is it saying is not defined...

If I know that I'd be half way home.
What references do you have selected?
I am guessing it's something to do the kernel32 but I repleced that
with full path C:\windows\system32 and it still didn't work :(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top