Find MAC Address using VBA

A MAC address is a unique ID assigned to a Network adapter & it stand for Media Access Control Address.

There can be more than MAC address possible for a computer, depending on the number of Network adapters available.

cmd prompt:  getmac

In command prompt type getmac and press enter. This will list the valid MAC addresses in your computer. To get it using VBA, use the following code.

Get MAC Addresses of all Network Adapters

The VBA code will query WMI management configuration to get all the list of MAC Addresses assigned to each adapter.

Use this code in your VBA project to get the list in sheet1.

Sub Get_MAC_Address_Network_oAdapterConf_Configuration()
    Dim iSh As Worksheet, i As Integer
    'Get All Network oAdapterConf Configuration Details
    Set iSh = ThisWorkbook.Sheets(1)
    Set wmi = GetObject("winmgmts:root\CIMV2")
    Set oAdapterConfs = wmi.ExecQuery("Select * from Win32_NetworkAdapterConfiguration")

    'Attributes of Each oAdapterConf Configuration
    iSh.Cells(1, 1) = "Description"
    iSh.Cells(1, 2) = "MACAddress"
    'Get MAC for Each Network oAdapterConf Attribute
    i = 2
    For Each oAdapterConf In oAdapterConfs
        With oAdapterConf
            iSh.Cells(i, 1) = .Description
            iSh.Cells(i, 2) = .MACAddress
        End With
        i = i + 1
End Sub

Some time programmers use it to identify whether the VBA app is running authorized computer. Within the code they will get this MAC address and cross reference against the list of MAC Address in their list.

Try this in any of your Windows machine. In most cases there will be more than one MAC Address possible.

So, design your app accordingly and do not rely only on one MAC Address.