R
Raymond Zeitler
When I use AppActivate to set focus to a console window started with
Shell, I receive runtime error 5. This doesn't occur when I put a
break point on the AppActivate statement and then resume.
dblPID = Shell("cmd.exe /k", vbNormalFocus)
AppActivate dblPID ' Runtime error 5
Is this a bug? I also tried putting in a for-next loop to insert a
delay between the statements. And in the real program, I have several
statements between the Shell and the AppActivate statements.
I'm trying to get the VBA code to wait for the shell call to complete
before certain statements get executed. Do I have to resort to using
an API shell call?
I'm running Win2000 SP4, Office 2000 SP3. Here's some simple code
that demonstrates how I think this should work, but note that the real
code uses the /c switch to cmd and includes several statements between
the Shell and AppActivate calls:
Private Sub cmdOK_Click()
Dim dblMinVal As Double
dblMinVal = Shell("cmd.exe /K", vbNormalFocus)
On Error Resume Next
Do
AppActivate dblMinVal
If Err.Number = 5 Then ' Console closed
Err.Clear
Exit Do
End If
Loop
On Error GoTo 0
MsgBox "You shouldn't see this message until " & _
"you close the console window, but you do!"
Unload frmMain
End Sub 'cmdOK_Click()
(Note that my real email address is rzeitler AT phonon DOT com.)
Shell, I receive runtime error 5. This doesn't occur when I put a
break point on the AppActivate statement and then resume.
dblPID = Shell("cmd.exe /k", vbNormalFocus)
AppActivate dblPID ' Runtime error 5
Is this a bug? I also tried putting in a for-next loop to insert a
delay between the statements. And in the real program, I have several
statements between the Shell and the AppActivate statements.
I'm trying to get the VBA code to wait for the shell call to complete
before certain statements get executed. Do I have to resort to using
an API shell call?
I'm running Win2000 SP4, Office 2000 SP3. Here's some simple code
that demonstrates how I think this should work, but note that the real
code uses the /c switch to cmd and includes several statements between
the Shell and AppActivate calls:
Private Sub cmdOK_Click()
Dim dblMinVal As Double
dblMinVal = Shell("cmd.exe /K", vbNormalFocus)
On Error Resume Next
Do
AppActivate dblMinVal
If Err.Number = 5 Then ' Console closed
Err.Clear
Exit Do
End If
Loop
On Error GoTo 0
MsgBox "You shouldn't see this message until " & _
"you close the console window, but you do!"
Unload frmMain
End Sub 'cmdOK_Click()
(Note that my real email address is rzeitler AT phonon DOT com.)