MAC address lookup in Excel – VBA code

What is MAC address? 

A media access control address (MAC address) is a unique identification assigned to a device network interface controller (NIC) for communication at the data link layer of a network segment. In simple words, this is a unique identification for a device or computer in a network for communication.

You can get more details about the MAC from here.

Use of MAC in Excel: 

The MAC address is technically a system identifier therefore you could use it in Excel,

  • To restrict the use of a particular Excel file in a particular system
  • It can also be used to generate the activation key for Excel based software that you distribute

Please leave a comment and share with others if you have any other use of MAC address.

How to get System MAC address in Excel VBA? 

The MAC address of a Windows system can be fetched using following visual basic code in Excel. This will get the MAC and display it in a message box. To use:

  • Copy and paste the below code into VBA code editor
  • Save file in .xlsm format
  • Enable macros to execute the VBA code

VBA Code for MAC address:

Sub Mac_ID()
Dim strCom As String
Dim objWMIService As Object
Dim colAdapters As Object
Dim objAdapter As Object
strCom = "."
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strCom & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objAdapter In colAdapters
MsgBox "MAC ID of this system : " & objAdapter.MACAddress
Next objAdapter
End Sub

You can also download our sample MAC ID excel file.

What the MAC address Fetcher Looks Like:

mac address

Leave a Comment