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 from here

Use of MAC in excel:

This address my have different usage technically but in Excel,

  • You can use this id to restrict the use of a particular file in a particular system.
  • This can also be used to generate the activation key for the excel software to use in a particular system.

You can comment and share with others if you have any other use of MAC .

How to get MAC address in excel VBA?

The MAC address of a windows system can be generated using following visual basic code in excel.

This code will generate MAC and display in a message box.

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

Download Sample excel file to generate MAC ID:

  • Copy and paste the above code in VBA code editor
  • save file in .xlsm format
  • enable macros to execute the VBA code
mac address
mac address sample file

Leave a Reply

Your email address will not be published. Required fields are marked *