UnProtection macro help

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
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.


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
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Shouldn't it be?

Rich (BB code):
If strName <> "2011" Or _
           strName = vbNullString Then
           Exit Sub
        Else
 
Upvote 0
Agghhh!!! Of course - because of the else statement - geez, I knew it was something simple. man am I embarrased (again) Thanks for the help VoG - sure appreciate it.
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top