Solved

Ping in VBA

Posted on 2013-06-24
4
3,443 Views
Last Modified: 2013-06-24
I have an Excel sheet with names of servers.  I would like to go down the list, ping the server, and get the return value.

Is there a way to ping a server in VBA?
0
Comment
Question by:patriotpacer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39271234
using wmi:

Function sPing(sHost) As String
 
    Dim oPing As Object, oRetStatus As Object
 
    Set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
      ("select * from Win32_PingStatus where address = '" & sHost & "'")
 
    For Each oRetStatus In oPing
        If IsNull(oRetStatus.StatusCode) Or oRetStatus.StatusCode <> 0 Then
            sPing = "Status code is " & oRetStatus.StatusCode
        Else
            sPing = "Pinging " & sHost & " with " & oRetStatus.BufferSize & " bytes of data:" & Chr(10) & Chr(10)
            sPing = sPing & "Time (ms) = " & vbTab & oRetStatus.ResponseTime & Chr(10)
            sPing = sPing & "TTL (s) = " & vbTab & vbTab & oRetStatus.ResponseTimeToLive
        End If
    Next
End Function

Sub TestPing()
    MsgBox sPing("www.microsoft.com")
End Sub

Open in new window


from http://social.technet.microsoft.com/Forums/scriptcenter/en-US/e59a38e1-eaf0-4b13-af10-fd4be559f50f/ping-from-vba-in-excel
0
 

Author Comment

by:patriotpacer
ID: 39271276
Thx, Sedwig.

But it's not giving me the IP back.
0
 

Author Closing Comment

by:patriotpacer
ID: 39271284
Wanna give you some points because you technically answered.

Thx
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

623 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