Solved

Ping in VBA

Posted on 2013-06-24
4
2,549 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
  • 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 Comment

by:patriotpacer
ID: 39271282
0
 

Author Closing Comment

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

Thx
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
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 …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

707 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

12 Experts available now in Live!

Get 1:1 Help Now