Hi, I found some code online some time back that allows me to maintain a list of PC names in Excel 2007, ping the PC to get the IP address and return the value in another column.
Sub GetCurrentIPs_OldDevices()
'Written: April 07, 2011
'Author: Leith Ross
'Summary: Reads the URLs on the ActiveSheet from column "A2" and returns the IP address.
' Headers are assumed to be in row 1.
' This works code with Windows XP and later.
Dim Cell As Range
Dim colPings As Object, objPing As Object, strQuery As String
Dim Rng As Range
Dim RngEnd As Range
Dim Wks As Worksheet
Set Wks = ActiveSheet
Set Rng = Wks.Range("A2")
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Wks.Range(Rng, RngEnd)
For Each Cell In Rng
'Define the WMI query
strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & Cell & "'"
'Run the WMI query
Set colPings = GetObject("winmgmts://./root/cimv2").ExecQuery(strQuery)
'Translate the query results to either True or False
For Each objPing In colPings
If Not objPing Is Nothing Then
Cell.Offset(0, 1) = objPing.ProtocolAddress
End If
Next objPing
Next Cell
End Sub
Now I would like to do the same thing for MAC Addresses and I found code that allows you to retrieve the local MAC address and returns the value in a text box.
Option Explicit
Sub testme01()
Dim strComputer As String
Dim objWMIService As Object
Dim colAdapters As Object
Dim objAdapter As Object
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objAdapter In colAdapters
MsgBox "Physical address: " & objAdapter.MACAddress
Next objAdapter
End Sub
My ultimate goal is to retrieve the MAC addresses from the list of PC names in column A and return the value in column B. I've tried adjusting the code that gets me the IP addresses of those PC names to replace the ping code with MAC address code instead but I must be doing something wrong because I can't quite get it to work. Hopefully someone can help get me there? Thanks in advance for any help!
Bookmarks