SaraWitch
Active Member
- Joined
- Sep 29, 2015
- Messages
- 377
- Office Version
- 365
- Platform
- Windows
Hello peeps,
I have two VBAs that protect and unprotect all worksheets in a workbook with a password. Is there a way of assigning these to a checkbox, so when the checkbox is selected all the sheets are protected and when deselected they are all unprotected (upon correct password entry).
The VBAs in 'ThisWorkbook' are:
Any help would be appreciated, thank you
I have two VBAs that protect and unprotect all worksheets in a workbook with a password. Is there a way of assigning these to a checkbox, so when the checkbox is selected all the sheets are protected and when deselected they are all unprotected (upon correct password entry).
The VBAs in 'ThisWorkbook' are:
VBA Code:
Sub protect_all_sheets()
top:
pass = InputBox("Password?")
repass = InputBox("Confirm password")
If Not (pass = repass) Then
MsgBox "You made a boo boo!"
GoTo top
End If
For i = 1 To Worksheets.Count
If Worksheets(i).ProtectContents = True Then GoTo oops
Next
For Each s In ActiveWorkbook.Worksheets
s.Protect Password:=pass
Next
Exit Sub
oops: MsgBox "I think you have some sheets that are already protected. Please unprotect all sheets then run this macro."
End Sub
Sub unprotect_all_sheets()
On Error GoTo booboo
unpass = InputBox("Please enter the password:")
For Each Worksheet In ActiveWorkbook.Worksheets
Worksheet.Unprotect Password:=unpass
Next
Exit Sub
booboo: MsgBox "There is a problem - check your password, caps lock, etc., then run this macro."
End Sub
Any help would be appreciated, thank you