Hi guys,
Could someone help me modify a little bit this code to suit my needs.
I would like the macro to check a range of cells and add the info ( false , true) next to the range that i am pinging.
i have a pourly code atempt :
Sub TestPinger()
Dim blnResponse As Boolean, lngStatus As ICMP_ECHO_REPLY
For Each tmpcell In Range("a1:a20").SpecialCells(2, 2)
If blnResponse = ping(tempcell, lngStatus) = True Then
tmpcell.Offset(0, 1) = "ok"
Else
tmpcell.Offset(0, 1) = "not ok"
End If
Next
I receive an error : Variable not defined.
Could someone help a noob to modify this code for my needs?

Originally Posted by
romperstomper
Not with that method, I don't think. You could use API functions instead - simplistic version below. The Ping function returns True if successful:
Option Explicit
Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long
Private Declare Function inet_addr Lib "WSOCK32.DLL" (ByVal cp As String) As Long
Private Declare Function IcmpCloseHandle Lib "icmp.dll" (ByVal IcmpHandle As Long) As Long
Private Declare Function IcmpSendEcho Lib "icmp.dll" _
(ByVal IcmpHandle As Long, _
ByVal DestinationAddress As Long, _
ByVal RequestData As String, _
ByVal RequestSize As Long, _
ByVal RequestOptions As Long, _
ReplyBuffer As ICMP_ECHO_REPLY, _
ByVal ReplySize As Long, _
ByVal timeout As Long) As Long
Private Type IP_OPTION_INFORMATION
Ttl As Byte
Tos As Byte
Flags As Byte
OptionsSize As Byte
OptionsData As Long
End Type
Public Type ICMP_ECHO_REPLY
address As Long
Status As Long
RoundTripTime As Long
DataSize As Long
Reserved As Integer
ptrData As Long
Options As IP_OPTION_INFORMATION
data As String * 250
End Type
Public Function ping(strAddress As String, Reply As ICMP_ECHO_REPLY) As Boolean
Dim hIcmp As Long
Dim lngAddress As Long
Dim lngTimeOut As Long
Dim strSendText As String
'Short string of data to send
strSendText = "blah"
' timeout value in ms
lngTimeOut = 1000
'Convert string address to a long
lngAddress = inet_addr(strAddress)
If (lngAddress <> -1) And (lngAddress <> 0) Then
hIcmp = IcmpCreateFile()
If hIcmp <> 0 Then
'Ping the destination IP
Call IcmpSendEcho(hIcmp, lngAddress, strSendText, Len(strSendText), 0, Reply, Len(Reply), lngTimeOut)
'Reply status
ping = (Reply.Status = 0)
'Close the Icmp handle.
IcmpCloseHandle hIcmp
Else
ping = False
End If
Else
ping = False
End If
End Function
Sub TestPinger()
Dim blnResponse As Boolean, lngStatus As ICMP_ECHO_REPLY
blnResponse = ping("10.100.1.1", lngStatus)
Debug.Print blnResponse
End Sub
Bookmarks