Protection‎ > ‎

All Sheets

To allow users to globally protect and unprotect all the worksheets in a workbook.

PROTECT ALL SHEETS
Using a double-password-verification method.

CODE:

Option Explicit

Sub ProtectAllSheets()
'JBeaucaire    4/1/2009
Dim pwd As String, pwd2 As String
Dim ws As Worksheet

    Do
        pwd = Application.InputBox("What password to use?", "Enter Password", Type:=2)
            If pwd = "False" Then Exit Sub
        pwd2 = Application.InputBox("Please enter the password again for verification?", "Re-Enter Password", Type:=2)
            If pwd2 = "False" Then Exit Sub
        If pwd = pwd2 Then Exit Do Else MsgBox "Passwords did not match, please try again"
    Loop
   
    For Each ws In Worksheets
        ws.Protect Password:=pwd
    Next ws

End Sub

























UNPROTECT ALL SHEETS
Password-verification method.

CODE:

Option Explicit

Sub UnProtectAllSheets()
'JBeaucaire    4/1/2009
Dim pwd As String, ws As Worksheet
On Error Resume Next

pwd = Application.InputBox("What password to use?", "Enter Password", Type:=2)
If pwd = "False" Then Exit Sub

    For Each ws In Worksheets
        ws.Unprotect Password:=pwd
        If ws.ProtectContents = True Then
            MsgBox "The password given was not correct"
            Exit Sub
        End If
    Next ws

End Sub


























Nothing says "thanks" like a steak dinner!

PayPal - The safer, easier way to pay online!

Comments