StuartKStout
New Member
- Joined
- Mar 28, 2017
- Messages
- 10
Hi
a Colleague wrote the below and has now left the company, I now need to expand the code so in cell.offset (0, 4) it will display the FQDN, is this possible?
The IPs start at Cell 'A2' and generally go down to row 254
Thanks in advance
Stuart
a Colleague wrote the below and has now left the company, I now need to expand the code so in cell.offset (0, 4) it will display the FQDN, is this possible?
The IPs start at Cell 'A2' and generally go down to row 254
Thanks in advance
Stuart
Code:
Sub PingTest()
Dim Cell As Range
Dim colPings As Object, objPing As Object, strQuery As String
Dim Rng As Range
Dim RngEnd As Range
Dim Wks As Worksheet
Set Wks = ActiveSheet
Set Rng = Wks.Range("A2")
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Wks.Range(Rng, RngEnd)
For Each Cell In Rng
'Define the WMI query
strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & Cell & "'"
'Run the WMI query
Set colPings = GetObject("winmgmts://./root/cimv2").ExecQuery(strQuery)
'Translate the query results to either True or False
For Each objPing In colPings
If Not objPing Is Nothing Then
Cell.Offset(0, 1) = objPing.ProtocolAddress
Cell.Offset(0, 2) = objPing.ResponseTime & " ms"
Cell.Offset(0, 3) = GetPingStatus(objPing.StatusCode)
'Cell.Offset(0, 4) = objPing.ResolveAddressName.Value
Exit For
End If
Next objPing
Next Cell
End Sub
Last edited by a moderator: