Kevin,
The Exec method is more convenient because you have immediate access to the
output stream (as well as the ability to supply an input stream or check
error output) but the Run method gives more control over the console window.
The disadvantage of the Run method is that you have to create a temporary
text file as a vehicle to capture the output text stream. Below is a
modification that should run the same ping command but keep the console
window completely hidden.
'------------------------------------
Sub FetchPingOutput()
Const window_hidden = 0
Const For_Reading = 1
Dim strLine As String
Dim R As Integer
R = 1
Set wsh = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
myTempName = fso.GetTempName()
wsh.Run "%comspec% /c ping 66.102.7.104 >" _
& myTempName, window_hidden, True
Set objTextFile = fso.OpenTextFile(myTempName, For_Reading)
Do While Not objTextFile.AtEndOfStream
strLine = objTextFile.ReadLine()
Cells(R, 1).Value = strLine
R = R + 1
Loop
objTextFile.Close
fso.DeleteFile (myTempName)
Set objTextFile = Nothing
Set wsh = Nothing
Set fso = Nothing
End Sub
'-----------------------------------
Steve Yandl