-1

I know absolutely nothing about VB but I'm trying to compile a quick ping test macro within a word document to test some malware sandbox software. However, I keep getting the runtime 424 error.

I've done a bit of research but with 0 knowledge of VB, I've failed to identify a solution. The code is as follows.

Sub Ping()

' Ping Macro

If My.Computer.Network.Ping("192.168.1.10") Then
  MsgBox ("Server pinged successfully.")
Else
  MsgBox ("Ping request timed out.")
End If

End Sub

I'm clearly missing something here. I assumed the object would have been the message box but I was wrong. Anybody know what I'm missing here?

EDIT: Debug shows the first line being the issue.

If My.Computer.Network.Ping("192.168.1.10") Then

Thanks.

R3uK
  • 14,417
  • 7
  • 43
  • 77
Sevaara
  • 55
  • 2
  • 9
  • Hey there, check out this post. http://stackoverflow.com/questions/21020077/ping-ip-address-with-vba-code-and-return-results-in-excel – Ryan Wildry Nov 04 '15 at 15:14
  • For an excel spreadsheet sure. I still have no idea what I'm doing with VBA, how would that translate into a Word macro? I'm not fussed about error handling, I literally just need to ping and watch the traffic in my VM. – Sevaara Nov 04 '15 at 15:19

1 Answers1

3

My.Computer.Network.Ping() is a VB.Net function and is not available in VBA.

From some time ago I have a function to get the ping time, this should get you going.
You probably need only the StatusCode = 0 check.

' strAddress = IP or name
Public Function PingTime(strAddress) As Long

    Dim objPing As Object, objStatus As Object

    ' Init: Assume error
    PingTime = -1

    On Error Resume Next
    Set objPing = GetObject("WinMgmts:{impersonationLevel=impersonate}").ExecQuery _
                           ("SELECT * FROM Win32_PingStatus WHERE Address = '" & strAddress & "' ")
    If Err.Number <> 0 Then
        Exit Function
    End If

    For Each objStatus In objPing
        If objStatus.StatusCode = 0 Then
            PingTime = objStatus.Properties_("ResponseTime").Value
            Exit For
        End If
    Next
    Set objStatus = Nothing
    Set objPing = Nothing

End Function
Andre
  • 26,751
  • 7
  • 36
  • 80