Greetings, I am trying to use this code to create a quick way of locking and unlocking a worksheet. The initial code was easy (ActiveSheet.Unprotect "2011"), the password being "2011"; and worked fine but then I thought I would like to add in an input box so that the user would have to type in the password. That did not work, I do not get an error message or anything - just nothing happens. I am guessing that my syntax is wrong, am I declaring the variables wrong or something?
I know that I am probably missing the obvious, but I am still learning the nuances of VBA so please forgive for a dumb question.
Thanks for your help, Rick
I know that I am probably missing the obvious, but I am still learning the nuances of VBA so please forgive for a dumb question.
Code:
Sub SheetUnprotectA()
'unlocks the sheet
Dim strName As String
strName = InputBox(Prompt:="Please enter the correct password to unlock the worksheet.", _
Title:="Unlock Sheet", Default:="enter unlock password")
If strName = "2011" Or _
strName = vbNullString Then
Exit Sub
Else
ActiveSheet.Unprotect "2011"
End If
End Sub
Thanks for your help, Rick