![]() |
Sub or Function not defined
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 |
Sub or Function not defined
It compiles for me... What is it saying is not defined...
-- HTH... Jim Thomlinson "oliver" wrote: 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 |
Sub or Function not defined
On 9 Aug, 18:24, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote: It compiles for me... What is it saying is not defined... -- HTH... Jim Thomlinson "oliver" wrote: 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 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 :( |
All times are GMT +1. The time now is 03:42 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com