I have a sheet which is locked before distributing to users. I need to put a button on it so that the users who know the password can only unlock the sheet, else if password is blank or wrong it will display ERROR message and terminate. Any code will be useful.
I have done something like this only insted of putting the code in the workbook I created an unlock file. If the user had the file installed they could lock and unlock the workbook by clicking a button. The drawback to this if an unapproved person acquired the password file they could unlock the workbook plus you have to redistribute the file whenever you changed the password or added files to the workbook list. The advantage it is quick to use and you don't have to remember or give out the password, just the unlock file. The key file is hidden from view to prevent viewing by the user. This is a shot of the workbook list where protected files are listed.
It can get fancier than this, but this is a fairly quick and dirty approach:
Private Sub CommandButton1_Click()
Dim ans As String
ans = InputBox("Please enter a password to unlock the sheet", "Password required")
If ans <> "bigdog" Then
MsgBox "Sorry Charlie, but you got it wrong", vbInformation + vbOKOnly, "Buy Bye"
Else: ActiveSheet.Unprotect "password"