Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Perl and Excel

86 views
Skip to first unread message

jonathan

unread,
Nov 20, 2001, 12:33:17 PM11/20/01
to
Hello,

I need to use VBA in Excel to run a Perl script which outputs data to
a tab delimmited file, and then load the file into Excel.

Unfortunately the Perl script finishes after Excel has tried to open
the file. Is there a way to get Excel to wait for Perl to finish???
I'm using the Shell command to run the shell script BTW.

Thanks!


Jon.

Jim Rech

unread,
Nov 20, 2001, 2:27:11 PM11/20/01
to
This may help:

Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long

Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, _
lpExitCode As Long) As Long

Public Const PROCESS_QUERY_INFORMATION = &H400
Public Const STILL_ACTIVE = &H103


Sub Test()
Dim StartTime As Double
StartTime = Now
ShellAndWait "calc.exe", 1
MsgBox "Gone " & Format(Now - StartTime, "s") & " seconds"
End Sub

'Window States (Per Help for Shell function):
' 1, 5, 9 Normal with focus.
' 2 Minimized with focus.
' 3 Maximized with focus.
' 4, 8 Normal without focus.
' 6, 7 Minimized without focus.
Sub ShellAndWait(ByVal PathName As String, Optional WindowState)
Dim hProg As Long
Dim hProcess As Long, ExitCode As Long

'fill in the missing parameter and execute the program
If IsMissing(WindowState) Then WindowState = 1
hProg = Shell(PathName, WindowState)

'hProg is a "process ID under Win32. To get the process handle:
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hProg)
Do
'populate Exitcode variable
GetExitCodeProcess hProcess, ExitCode
DoEvents
Loop While ExitCode = STILL_ACTIVE
End Sub

--
Jim Rech
Excel MVP

0 new messages