Use one of these methods to wait for shell process end.
You could even 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))