How to Use a VBA to Find a Mac Address

binary - o2 image by samantha grandy from Fotolia.com

It's valuable to know how to check the Media Access Control (MAC) address using Visual Basic for Applications (VBA) when you're setting up multiple adaptors. Every adaptor has a permanent unique identification number known as a MAC address. The MAC address is used to identify the adaptor in a computer network.

The number is 12 characters, with both numbers and letters, separated by dashes or colons. You can easily check the MAC address by creating a simple function using VBA.

Open Microsoft Excel 2007 and type "Function GetMACAddress()" and press "Enter" to create a new function.

Type "Dim objVMI As Object

  • It's valuable to know how to check the Media Access Control (MAC) address using Visual Basic for Applications (VBA) when you're setting up multiple adaptors.
  • You can easily check the MAC address by creating a simple function using VBA.

Dim vAdptr As Variant

Dim objAdptr As Object

Dim adptrCnt As Long" to create your variables.

Type "Set objVMI = GetObject("winmgmts:\" & "." & "\root\cimv2")

Set vAdptr = objVMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")" to define your adaptor objects.

Type "For Each objAdptr In vAdptr

  • Dim vAdptr As Variant Dim objAdptr As Object Dim adptrCnt As Long" to create your variables.
  • \root\cimv2") Set vAdptr = objVMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")" to define your adaptor objects.

Next" to loop through the network adaptors in your system and get your MAC address.

Type "End Function" if necessary and run your function. You will see a message with your MAC address.

×