Thread: IP Address
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Steve Yandl[_3_] Steve Yandl[_3_] is offline
external usenet poster
 
Posts: 117
Default IP Address

Sam,

Provided the PCs are XP or later, this might do what you want:

'------------------------------------

Sub GetIPaddy()

Dim strIPAddress As String
Dim strComputerName As String

strComputerName = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputerName &
"\root\cimv2")

Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled =
True")

For Each objItem In colItems
For Each objAddress In objItem.IPAddress
strIPAddress = objAddress
Next
Next

MsgBox strIPAddress

Set colItems = Nothing
Set objWMIService = Nothing

End Sub


'------------------------------------

Steve Yandl



"Sam Wilson" wrote in message
...
Not as straight forward as I'd guessed!

"Rob Bovey" wrote:

"Sam Wilson" wrote in message
...
How can I get my the IP address of a computer using VBA? I was hoping
it'd
be through environ() but it seems not...


Hi Sam,

I've posted an example of how to do this he

http://appspro.com/Tips/NetworkTips.htm#NT2

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Professional Excel Development - Second Edition *
http://www.appspro.com/Books/ProExcelDev.htm