How to run ping commands from Excel?

Posted on 2007-10-04
Last Modified: 2011-10-03
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?
Question by:joeybeeble
    LVL 33

    Accepted Solution

    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()
    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."
               Cells(i, 3) = strComputer & " responded to ping."
            End If
            Cells(i, 3) = strComputer & " did not respond to ping."
        End If

    End Sub


    Author Comment

    That is exactly what I was looking for.  Thanks!
    LVL 33

    Expert Comment

    Thanks for the grade!
    It was a pleasure to help.


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    How to debug this code 7 33
    VBA to sum a column 13 30
    Complex Lookup Formulas 3 30
    Min Month 11 30
    Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
    This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
    The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
    The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now