get my public IP address with a function (1 Viewer)

duke217

Registered User.
Local time
Today, 16:00
Joined
Jan 23, 2018
Messages
17
Hi,

I found this function to get my public IP:
Code:
Function GetMyPublicIP() As String
 
    Dim HttpRequest As Object
 
    On Error Resume Next
    'Create the XMLHttpRequest object.
    Set HttpRequest = CreateObject("MSXML2.XMLHTTP")
 
    'Check if the object was created.
    If Err.Number <> 0 Then
        'Return error message.
        GetMyPublicIP = "Could not create the XMLHttpRequest object!"
        'Release the object and exit.
        Set HttpRequest = Nothing
        Exit Function
    End If
    On Error GoTo 0
 
    'Create the request - no special parameters required.
    HttpRequest.Open "GET", "http://myip.dnsomatic.com", False
 
    'Send the request to the site.
    HttpRequest.Send
 
    'Return the result of the request (the IP string).
    GetMyPublicIP = HttpRequest.ResponseText
 
End Function

Now, it all looks very nice and all, but how do I get the result from that function? i.e. I would like the IP address displayed on a report...

Thank you!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:00
Joined
Oct 29, 2018
Messages
21,358
Hi. Have you tried simply using a Textbox with the following Control Source?
Code:
=GetMyPublicIP()
 

duke217

Registered User.
Local time
Today, 16:00
Joined
Jan 23, 2018
Messages
17
I knew it had to be extremely simple :D

Thanks a LOT
 

Users who are viewing this thread

Top Bottom