LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default AppActivate runtime error 5 when used with shell cmd

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.)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
xpath error? Runtime Error 13 type mismatch Steve M[_2_] Excel Discussion (Misc queries) 0 January 17th 08 01:16 AM
Runtime error '1004' General ODBC error star_lucas New Users to Excel 0 August 29th 05 04:09 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM
Unknown where is the problem on the Runtime error - Automation error wellie Excel Programming 1 July 10th 03 08:12 AM


All times are GMT +1. The time now is 06:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"