Hi,
I am using the below VBA code to lock and unlock a number of sheets in my workbook using 2 separate buttons on an index page. The code works perfectly. The only issue is that I want to set the password in the code rather than have a new one entered each time i lock the sheets. (My worry is that someone other than me who is required to use this document will accidentally enter a miss spelt password and lock everyone out)
I've tried amending the code but had no joy.
Can anyone help with this -
Sub Button1_Click()
Dim wSheet As Worksheet
Dim Pwd As String
Pwd = InputBox("Enter your password to unprotect all worksheets", "Password Input")
On Error Resume Next
For Each wSheet In Worksheets
wSheet.Unprotect Password:=Pwd
Next wSheet
If Err <> 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be unprotected.", vbCritical, "Incorect Password"
End If
On Error GoTo 0
End Sub
Sub Button2_Click()
Dim wSheet As Worksheet
Dim Pwd As String
Pwd = InputBox("Enter your password to protect all worksheets", "Password Input")
For Each wSheet In Worksheets
wSheet.Protect Password:=Pwd
Next wSheet
End Sub
Bookmarks