Solved

Ping in VBA

Posted on 2013-06-24
4
3,126 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 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

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.

Question has a verified solution.

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

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

756 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