I didn't show the loop...lots of extra code. But I think you can just assume the cmd (shell) is being run inside the loop.
MeShellAndWait is the function runs the shell. Maybe there can be an adjustment there?
Function MeShellAndWait(szCommandLine As String, Optional iWindowState As Integer = vbHide) As Boolean
Dim lResult As Long
Dim lTaskID As Long
Dim lProcess As Long
Dim lExitCode As Long
On Error GoTo ErrorHandler
lTaskID = Shell(szCommandLine, iWindowState)
If lTaskID = 0 Then Err.Raise 9999, , "Shell function error."
lProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0&, lTaskID)
If lProcess = 0 Then Err.Raise 9999, , "Unable to open Shell process handle."
Do
'lExitCode will be set to STILL_ACTIVE as long as the shelled process is running.
lResult = GetExitCodeProcess(lProcess, lExitCode)
DoEvents
Loop While lExitCode = STILL_ACTIVE
MeShellAndWait = True
Exit Function
ErrorHandler:
gszErrMsg = Err.Number
MeShellAndWait = False
End Function
p45cal: I went ahead and tried all the options. Was worth a shot, but no luck. Every time the CMD window gets called, Excel becomes the active window.