Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4457
  • Last Modified:

Ping in VBA

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
patriotpacer
Asked:
patriotpacer
  • 3
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
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
 
patriotpacerAuthor Commented:
Thx, Sedwig.

But it's not giving me the IP back.
0
 
patriotpacerAuthor Commented:
0
 
patriotpacerAuthor Commented:
Wanna give you some points because you technically answered.

Thx
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.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now