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

Thank you. I am sure I tried something similar before asking the question.
The laptops seem to have scripting locked on user accounts. I need to run
the audit from user logon ... I plan to try again with your code on the slim
chance I did something wrong before.

--
Steve

"Steve Yandl" wrote in message
...
Steve,

Here is an alternate approach which is a VBA adaption of a vbScript I use.
In the example, I simply have the output placed on the active sheet in
Column A beginning at row 1 but that is all pretty easy to modify.

'--------------------------------------
Sub RunIPCONFIG()
Dim r As Integer
Dim strLine As String
Set wsh = CreateObject("WScript.Shell")
Set wshExec = wsh.Exec("ipconfig /all")
Set objStdOut = wshExec.StdOut
r = 1

Do Until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
Cells(r, 1).Value = strLine
r = r + 1
Loop

Set wshExec = Nothing
Set wsh = Nothing
End Sub


'--------------------------------------

Steve Yandl



"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