SaraWitch
Active Member
- Joined
- Sep 29, 2015
- Messages
- 378
- Office Version
- 365
- Platform
- Windows
Hello peeps,
I am using a VBA to protect all my sheets, which works a treat. However, I would like protect them all bar one and this isn't working:
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 try again."
Next
Sheets("Sheet2").Unprotect:="1234" I think this is the problem line!
End Sub
And my multiple unprotect sheets is:
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 locks, etc., then try again."
End Sub
Ta muchly, folks!
I am using a VBA to protect all my sheets, which works a treat. However, I would like protect them all bar one and this isn't working:
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 try again."
Next
Sheets("Sheet2").Unprotect:="1234" I think this is the problem line!
End Sub
And my multiple unprotect sheets is:
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 locks, etc., then try again."
End Sub
Ta muchly, folks!