Link to home
Start Free TrialLog in
Avatar of prodempsey
prodempseyFlag for United States of America

asked on

Excel Use VBA to get user's Mac Address for their computer

Does anyone know how to use VBA to get a user's MAC Address from their computer, no matter what version of Windows or OS their using?

Here's an article I found on how to look up the MAC Address manually:

https://networking.grok.lsu.edu/article.aspx?articleid=17135
Avatar of Jan Janßen
Jan Janßen
Flag of Germany image

You could try something like
Private Function getMacAddress() As String
    Try
        Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
        Dim adapter As NetworkInterface
        Dim myMac As String = String.Empty

        For Each adapter In adapters
            Select Case adapter.NetworkInterfaceType
                'Exclude Tunnels, Loopbacks and PPP
                Case NetworkInterfaceType.Tunnel, NetworkInterfaceType.Loopback, NetworkInterfaceType.Ppp
                Case Else
                    If Not adapter.GetPhysicalAddress.ToString = String.Empty And Not adapter.GetPhysicalAddress.ToString = "00000000000000E0" Then
                        myMac = adapter.GetPhysicalAddress.ToString
                        Exit For ' Got a mac so exit for
                    End If

            End Select
        Next adapter

        Return myMac
    Catch ex As Exception
        Return String.Empty
    End Try
End Function

Open in new window

Avatar of prodempsey

ASKER

Do I have to add a reference in order to make it work and does your UDF need any arguments?
SOLUTION
Avatar of prodempsey
prodempsey
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Closing question as I found the solution I needed in the article posted above.  Thanks For assisting Jan.