Solved Automatically Add the IP Address into table

gstylianou

Registered User.
Local time
Today, 17:41
Joined
Dec 16, 2013
Messages
359
Good evening to forum,

A quick question I would like to ask to the most experienced friends with Vba. Is there a way to find automatically the IP and then input into a table by using a command button?

There is a special reason I need it and I will appreciate any help

Thanks in advance
 
I use the following functions to get local IP and Public IP in several of my apps
For example, the 'Add a bit more Drama' section of my Attention Seeking example app

SQL:
Function GetMyLocalIP() As String

    'Declaring the necessary variables.
    Dim strComputer     As String
    Dim objWMIService   As Object
    Dim colItems        As Object
    Dim objItem         As Object
    Dim myIPAddress     As String
   
    'Set the computer.
    strComputer = "."
   
    'The root\cimv2 namespace is used to access the Win32_NetworkAdapterConfiguration class.
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
   
    'A select query is used to get a collection of IP addresses from the network adapters that have the property IPEnabled equal to true.
    Set colItems = objWMIService.ExecQuery("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
   
    'Loop through all the objects of the collection and return the first non-empty IP.
    For Each objItem In colItems
        If Not IsNull(objItem.IPAddress) Then myIPAddress = Trim(objItem.IPAddress(0))
        Exit For
    Next
   
    'Return the IP string.
    GetMyLocalIP = myIPAddress
   
   ' Debug.Print GetMyLocalIP
   

End Function

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
 

Users who are viewing this thread

Back
Top Bottom