Reliable send keys
Thank you. If you mean along the lines of Steve Yandl's reply, I tried
something similar before asking the question. It worked great on my home PC
but failed to run on the laptops that require audit. These are locked down
tight.
I since discovered the precise moment the code was passed by watching the
Excel status bar when the cmd window (supposedly) had focus. This led to me
touching the cmd window with the mouse before it fired (why is that not a
logical step <g). This made the command pass every time. So, this issue
seems to be that the cmd window is either not achieving focus or is losing
focus - despite outward appearances. I guess the next logical question is
how to check whether cmd has focus and switch focus if it does not have it.
--
Steve
"Peter T" <peter_t@discussions wrote in message
...
SendKeys is unreliable at the best of times and even more dodgy with the
command window. Why not pipe the results of ipconfig to a text file with
the Shell (and use vbHide), then open the text file in notepad or even
directly into cells. Post back if not sure how to do that.
Regards,
Peter T
"AltaEgo" <Somewhere@NotHere wrote in message
...
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
|