Sunday, July 20, 2014

Utility to Automatically get the MAC Address(Physical Address) using Excel Interface

Below Code will Automatically get the MAC Address in Excel U I Form

intCount = 0
strMAC = ""
' We're interested in MAC addresses of physical adapters only

strQuery = "SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID > ''"

Set objWMIService = GetObject("winmgmts://./root/CIMV2")
Set colItems = objWMIService.ExecQuery(strQuery, "WQL", 48)

For Each objItem In colItems
    If InStr(strMAC, objItem.MACAddress) = 0 Then
        strMAC = strMAC & "," & objItem.MACAddress
        intCount = intCount + 1
    End If
Next
' Remove leading comm
If intCount > 0 Then strMAC = Mid(strMAC, 2)
strMAC = Split(strMAC, ",")

TextBox1.Text = Trim(Replace(strMAC(0), ":", "")) ' Excel Text Boxes

TextBox1.Enabled = False   ' Excel Text Boxes


No comments:

Post a Comment