calling a server-side perl script from within VBA

G

Gary Hillerson

I need to call a server-side perl script provided by someone else from
within my VBA code (in a Word template).

I know nothing about COM. And this template gets used by people in a
variety of Word/Windows configurations -- Word 2000 or later on
Windows 98 or later.

I can call LaunchURL (from shell32.dll) to open a browser to a web
site. Is there something similar I can use to call a perl script and
get back a result?

thanks in advance,
gary hillerson
 
R

Russ

Gary,
You could call a dos batch file from VBA.
Helmut Weber mentioned this:
<http://vb.mvps.org/samples/project.asp?id=Shell32>



Or this xShell code works in Word97, too:

Put this in Declarations section at the top of your VBA code module so that
all subroutines can take advantage of the 'wait for shell' code.

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

'Add this code as one of the regular subroutines.

Public Function ShellX( _
ByVal PathName As String, _
Optional ByVal WindowStyle As Integer = 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

'And call it like this:

Dim x As Long
Dim strDosBatchFullPath As String
strDosBatchFullPath = ³C:\...myDosBatchFile.bat²
System.Cursor = wdCursorWait
x = ShellX(Chr(34) & strDosBatchFullPath & Chr(34))
 
G

Gary Hillerson

Hey Russ,

Thanks so much.

I'm just back from vacation, and will stab at this in the next few
days, but it sure makes sense. So thanks again,

gary
 

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