What is my Public IP Address?
There are no direct methods to get public ip address in VBA.
This has to be done by using a web service using below steps:
- Open IE Explorer from VBA Code.
- Navigate to this page -> What is my Ip?
- Wait for page to load
- Get IP address displayed in page.
So, what is does is actually extract IP address displayed external web site.
VBA Get My IP
Here is the code to display the ip address.
Public Sub Whatismyip() 'Define Data type for Variable Fields Dim inetApp As Object Dim sURL As String 'Set URL to What is my ip page sURL = "https://officetricks.com/what-is-my-ip-address/" 'Create IE & Navigate Set inetApp = CreateObject("InternetExplorer.Application") inetApp.Visible = True inetApp.navigate sURL DoEvents Application.Wait DateAdd("s", 1, Now) Do While inetApp.busy Application.StatusBar = "Application Loading. Please Wait..." Application.Wait DateAdd("s", 1, Now) DoEvents Loop 'Get the IP Set t0 = inetApp.document.getElementsByClassName("whatismyip") For Each t1 In t0 Debug.Print t1.innertext 'or 'MsgBox t1.innertext Exit For Next End Sub
You have plenty of methods available to get local ip address like cmd->ipconfig or windows management etc.,