Unprotect/Protect

Quietus

New Member
Joined
Feb 5, 2018
Messages
16
I have a work book that has multiple Sheets in it (32sheets total). Now each one of them have a protect sheet with password to unprotect. They all have the same password. My question is there any way to protect the entire work book with the same settings(Select Unlocked Cells, Format Cells, edit Objects) with having to only enter in password once to unlock all the sheets? Or is the only way to unlock and lock each sheet separately?

Thanks in advance for any and all help.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hello,

You could create a new Module, and use the code below:

Code:
Option Explicit


Const strPassword As String = "Unlock"


Sub LockAll()
    Dim ws As Worksheet
    
    For Each ws In ThisWorkbook.Worksheets
        ws.Protect Password:=strPassword
    Next ws
End Sub


Sub UnlockAll()
    Dim ws As Worksheet
    
    For Each ws In ThisWorkbook.Worksheets
        ws.Unprotect Password:=strPassword
    Next ws
End Sub

The password for the sheets is currently set as "Unlock", change this to whatever you want. There are obviously 2 sub-routines, one to lock all worksheets, and one to unlock all worksheets.

Hope that helps

Caleeco
 
Upvote 0
You can use one subroutine for both cases

Code:
Sub LockAll(Byval b as Boolean)
[LEFT][COLOR=#333333][FONT=monospace]Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
    If b Then ws.Protect strPassword Else [COLOR=#333333][FONT=monospace]ws.Unprotect strPassword
[/FONT][/COLOR]Next
[/FONT][/COLOR][/LEFT]
End Sub

where
LockAll True
locks and
LockAll False
unlocks.
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,970
Members
448,933
Latest member
Bluedbw

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