这使用了该网站的HTML抓取:
http://whatismyipaddress.com/
如果您熟悉String操作,则可以更改代码以与其他站点一起使用
将其粘贴到模块中并运行。
干杯!
行程
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Dim tempString As String
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Sub WhatsMyIP()
Dim StartingPoint As Long
Dim EndPoint As Long
Dim i As Integer
Dim IPAddress As String
DownloadFile "http://whatismyipaddress.com/", "c:\tempfile.txt"
Open "c:\tempfile.txt" For Random As #1 Len = 30000
Get #1, 1, tempString
Close #1
StartingPoint = InStr(1, tempString, """LOOKUPADDRESS"" value=""", vbTextCompare)
StartingPoint = StartingPoint + Len("""LOOKUPADDRESS"" value=""")
EndPoint = InStr(1, Mid(tempString, StartingPoint, 25), """ max", vbTextCompare)
IPAddress = Mid(tempString, StartingPoint, EndPoint - 1)
MsgBox "Your External IP Address is: " & IPAddress
End Sub
From: https://bytes.com/topic/access/insights/940497-how-get-external-ip-address-via-vb-vba