View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
AltaEgo AltaEgo is offline
external usenet poster
 
Posts: 245
Default Reliable send keys

Hello

I use the code below to open and run ipconfig /all to file. It woks fine on
my laptop but is hit-and-miss on other laptops, sometimes running; sometimes
producing Enter only; sometimes nothing more than the open cmd window. Is
there a way to ensure the code does its job? I was thinking of While Dir
produces nothing and shortening the wait time but the thought of the
SendKeys disappearing into buffers or elsewhere worries me - running the
code in break mode experience :-) Is there another way?


Sub RunCMD()
Dim ReturnValue

sCmd = "ipconfig /all " & ActiveWorkbook.Path & "\" & fName & " {ENTER}"

ReturnValue = Shell("CMD.EXE", 1)

' possibly, While the file doesn't exist
Application.OnTime Now + TimeSerial(0, 0, 5), "typeKeys" ' reduce 5 to 1?
'Wend
End Sub



Private Sub typeKeys()
SendKeys sCmd
End Sub


--
Steve