I have a vba form . I wanted to know if there's a way for it to run only in a single computer so that if someone want's to copy it they cannot run it on another machine. I'm thinking maybe we can use a computer's mac address as a mode of security.
Anyone?
EDIT: implemented example from miroxlav's answer:
Const AllowedName As String = "CEB-L1-7440236"
Sub UserForm_click()
If Environ$("COMPUTERNAME") <> AllowedName Then
MsgBox ("Not authorized.")
Exit Sub
End If
If vbYes <> MsgBox("Launch the macro?", vbYesNo) Then Exit Sub
'--start of code what macro actually does
'....
'....
'....
'--end of code what macro actually does
MsgBox ("Finsihed.")
End Sub
Maybe you would want to lock the macro rather to user name than to computer name (so the authorized user can use it on any computer), but it's on you.
Example - inset
Const
line at the top of your macro module andIf
...EndIf
just after yourSub
macro line:But this one can be relatively easily circumvented using command line:
once someone knows that
abcd
is proper computer name needed to run the macro. Perhaps prefer user name checking. Relevant code line will change to:Of course, you can also get computer's MAC address using VBA, just search "mac address vba", there are many examples.