最简单办法:
Dim h As Object, s As String
Set h = CreateObject("Microsoft.XMLHTTP")
h.Open "GET", "http://www.ip138.com/ip2city.asp", False
h.Send
If h.ReadyState = 4 Then
s = StrConv(h.Responsebody, vbUnicode)
End If
If InStr(s, "[") > 0 And InStr(s, "]") > 0 Then
MsgBox Split(Split(s, "[")(1), "]")(0)
Else
MsgBox "IP获取失败"
End If