Philippe,
Here is code I use recursively to run a series of DOS Commands in a Command
Prompt Window:
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2004 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Const WAIT_INFINITE = -1&
Private Const SYNCHRONIZE = &H100000
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
' Copyright ©1996-2004 VBnet, Randy Birch, All Rights Reserved.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub AllSub()
Dim q As String
Dim r As Integer
Dim s As String
Dim x As String
Dim dStarted As Date
Dim dEnded As Date
Dim lDiff As Long
Dim hProcess As Long
Dim taskId As Long
Dim cmdline As String
Sheets("PleaseWait").Visible = True
Application.Goto Reference:="PleaseWait"
Application.ScreenUpdating = False
r = 1
x = Range("LoopHold") ' This is variable that identifies last button
used; maximum counter
On Error Resume Next
Worksheets("macros").Range("GroupTime").ClearContents
Do Until r = x + 1
s = "Title" & r & "TimeHold"
Worksheets("macros").Range("Counter").Value = r
q = Range("ShellHold") ' This captures all switches chosen by user
to pass variables to batch file
dStarted = Now()
If Range("AllTitleHold") <> 0 Then taskId = Shell(q) ',
vbMinimizedNoFocus)
Application.Calculate
hProcess = OpenProcess(SYNCHRONIZE, True, taskId)
Call WaitForSingleObject(hProcess, WAIT_INFINITE)
CloseHandle hProcess
r = r + 1
dEnded = Now()
lDiff = DateDiff("S", dStarted, dEnded)
Application.Calculate
Range(s).Value = lDiff
Loop
Worksheets("macros").Range("AllTitleHold1").Value = ""
Call HideSheets
ThisWorkbook.Activate
End Sub
I add a timer to each process so I know how long each takes and how long the
whole process takes so that I can schedule accordingly.
I hope this helps.
Michael
(e-mail address removed)