通过VBA代码,直接可以获取本机的IP地址。代码如下:
ComputerName = "localhost"
Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate}//" & ComputerName).ExecQuery("SELECT index, IPAddress FROM Win32_NetworkAdapterConfiguration")
For Each OpSys In OpSysSet
If TypeName(OpSys.IPAddress) <> "Null" Then
For Each IP In OpSys.IPAddress
MsgBox IP, 64, "IP地址"
Next
End If
Next
经过本站严格测试,代码正确。