In the sheet module put:
Private Sub Worksheet_Change(ByVal Target As Range)
'
' Macro by Joseph S. Was
'
Application.EnableEvents = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="admin"
Application.EnableEvents = True
End Sub
Then in a module add the unlock code and attach your code, if any, before the End Sub.
Note: You can run the un-lock code from a Form-Button or use a hot-key with Macros-Macro-select macro-Options-select your key.
Sub myUnLock()
'This code will unprotect the sheet.
Application.EnableEvents = False
Application.DisplayAlerts = False
ActiveSheet.Unprotect ("admin")
'Add optional code here!
Application.EnableEvents = True
Application.DisplayAlerts = True
End Sub
Then run your code out of the unlock sub, the first macro will password lock the code behind you automatically. You can make the password anything you want. To help hide your password you can password lock your macros form the VBA editor pull-down menu!
Note: this uses hard coded password protection which will decrease the security of the protection. But then again a password does not really deter someone from getting in if they want to, like a door lock does not stop some one from getting in a window, but does stop the causal passer-by from coming in. JSW