• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4321
  • 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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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