Mac Address (1 Viewer)

mester

Member
Local time
Today, 17:31
Joined
Apr 2, 2020
Messages
63
Hi everyone

Can we get the mac address using vba access plz
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:31
Joined
Sep 21, 2011
Messages
14,350
Have you looked through the Similar Threads at the bottom of this one?
 

mester

Member
Local time
Today, 17:31
Joined
Apr 2, 2020
Messages
63
Have you looked through the Similar Threads at the bottom of this one?
yes i am looking at them. have you tried them before?
 

isladogs

MVP / VIP
Local time
Today, 17:31
Joined
Jan 14, 2017
Messages
18,246
The easy way would be to try them out for yourself 😉
I haven't looked at the threads but this is the function I use. It works
Place it in a standard module

Code:
Function GetMyMACAddress() As String

    'Declaring the necessary variables.
    Dim strComputer     As String
    Dim objWMIService   As Object
    Dim colItems        As Object
    Dim objItem         As Object
    Dim myMACAddress    As String
    
    'Set the computer.
    strComputer = "."
    
    'The root\cimv2 namespace is used to access the Win32_NetworkAdapterConfiguration class.
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    
    'A select query is used to get a collection of network adapters that have the property IPEnabled equal to true.
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
    
    'Loop through all the collection of adapters and return the MAC address of the first adapter that has a non-empty IP.
    For Each objItem In colItems
        If Not IsNull(objItem.IPAddress) Then myMACAddress = objItem.MACAddress
        Exit For
    Next
    
    'Return the IP string.
    GetMyMACAddress = myMACAddress
  '  Debug.Print GetMyMACAddress

End Function
 

mester

Member
Local time
Today, 17:31
Joined
Apr 2, 2020
Messages
63
The easy way would be to try them out for yourself 😉
I haven't looked at the threads but this is the function I use. It works
Place it in a standard module

Code:
Function GetMyMACAddress() As String

    'Declaring the necessary variables.
    Dim strComputer     As String
    Dim objWMIService   As Object
    Dim colItems        As Object
    Dim objItem         As Object
    Dim myMACAddress    As String
   
    'Set the computer.
    strComputer = "."
   
    'The root\cimv2 namespace is used to access the Win32_NetworkAdapterConfiguration class.
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
   
    'A select query is used to get a collection of network adapters that have the property IPEnabled equal to true.
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
   
    'Loop through all the collection of adapters and return the MAC address of the first adapter that has a non-empty IP.
    For Each objItem In colItems
        If Not IsNull(objItem.IPAddress) Then myMACAddress = objItem.MACAddress
        Exit For
    Next
   
    'Return the IP string.
    GetMyMACAddress = myMACAddress
  '  Debug.Print GetMyMACAddress

End Function
Thank you so much
 

Users who are viewing this thread

Top Bottom