View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default SendKeys not sending to Cmd.exe

This worked for me -

Sub test()
Dim ReturnValue
ReturnValue = Shell("CMD.EXE", 5)

Application.OnTime Now + TimeSerial(0, 0, 1), "typeKeys"
End Sub

Sub typeKeys()
SendKeys "ipconfig /all {ENTER}", True

' MsgBox "done"

End Sub

Note SendKeys might not work at all in Vista.

Shame there doesn't seem to be a way to write the report to file. If so
could close the dos window and read the report back into VBA.

Regards,
Peter T

"AltaEgo" <Somewhere@NotHere wrote in message
...
Hi all
W7
XL2007
(same problem on XP. 2003)
Cannot use Cscript or Wscript.

I need to send some commands to a command window. Tested this code (and
variations). The Cmd window receives no keystrokes but the Msgbox pops up.




Sub test()
Dim ReturnValue
ReturnValue = Shell("CMD.EXE", 5)
'AppActivate ReturnValue
'will err when uncommented
SendKeys "ipconfig /all {ENTER}", True

MsgBox "done"

End Sub



--
Steve