How to run ping commands from Excel?

I want to be able to ping from Excel 2007.  Column A should be a list of computer names, column B should use CONCATENATE to put that computer name in a string "ping -n 1 ComputerName >> C:\results.txt".  I would like to make a macro that would run those pings in order, going down Column B.  Is that possible?  I haven't been able to find any information about running pings from Excel so far.

Also, if it is possible to run the pings, would it be possible to have the results put in Column C for that computer name?
joeybeebleAsked:
Who is Participating?
 
Jeroen RosinkSoftware testing consultantCommented:
perhaps this macro does what you need:

To look in Column B and return the results into Column C you might think of using tomsehing like this: (include the function mentioned above in the module)


Sub PingPcForRestults()
'http://msdn2.microsoft.com/en-us/library/aa394595.aspx
Dim RowsB As Long

RowsB = Cells(Rows.Count, 2).End(xlUp).Row
For i = 1 To RowsB

    If Cells(i, 2) <> "" Then
    strComputer = Cells(i, 2)
   
    '"ping -n 1 ComputerName >> C:\results.txt".
    Set objShell = CreateObject("WScript.Shell")
    Set objScriptExec = objShell.Exec( _
        "ping -n 2 -w 1000 " & strComputer & " >> C:\results.txt")
    strPingResults = LCase(objScriptExec.StdOut.ReadAll)
    If InStr(strPingResults, "reply from") Then
        If InStr(strPingResults, "destination net unreachable") Then
            Cells(i, 3) = strComputer & "did not respond to ping."
        Else
           Cells(i, 3) = strComputer & " responded to ping."
        End If
    Else
        Cells(i, 3) = strComputer & " did not respond to ping."
    End If

Next
End Sub


regards,
Jeroen
0
 
joeybeebleAuthor Commented:
That is exactly what I was looking for.  Thanks!
0
 
Jeroen RosinkSoftware testing consultantCommented:
Thanks for the grade!
It was a pleasure to help.

regards,
Jeroen
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.