Can anyone help with this please?
I want to extract the MAC address (used for IP) then store this value after Excel is closed down. On reopening I'd like to check that the previously stored MAC address = the current MAC address. Ideally I'd like this to work in an Add-In xlam rather than an xlsm, in case this has a bearing on where the MAC address value needs to be stored. The same macro would be run each subsequent time the Add-in is used, checking the MAC address each time.
I'm using this code to obtain and display the MAC address:
I have tried various methods to save the myMAcAddress value after closing Excel then retrieving it on re-opening with no success so far.
Also I am aware that the code to do this will need to include an if clause to deal with the first run where myMAcAddress value will be empty.
Any help is much appreciated
I want to extract the MAC address (used for IP) then store this value after Excel is closed down. On reopening I'd like to check that the previously stored MAC address = the current MAC address. Ideally I'd like this to work in an Add-In xlam rather than an xlsm, in case this has a bearing on where the MAC address value needs to be stored. The same macro would be run each subsequent time the Add-in is used, checking the MAC address each time.
I'm using this code to obtain and display the MAC address:
Code:
Sub Get_MACAddress()
Call GetMACAddress2(myMAcAddress)
If Len(myMAcAddress) < 4 Then
MsgBox "Please check your internet connection and try again"
Else
MsgBox myMAcAddress
End If
End Sub
Function GetMACAddress2(myMAcAddress) As String
Dim sComputer As String
Dim oWMIService As Object
Dim cItems As Object
Dim oItem As Object
sComputer = "."
Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Set cItems = oWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each oItem In cItems
If Not IsNull(oItem.IPAddress) Then myMAcAddress = oItem.macAddress
Exit For
Next
GetMACAddress2 = myMAcAddress
End Function
I have tried various methods to save the myMAcAddress value after closing Excel then retrieving it on re-opening with no success so far.
Also I am aware that the code to do this will need to include an if clause to deal with the first run where myMAcAddress value will be empty.
Any help is much appreciated