If you want to protect or unprotect all worksheets in Excel, you only can do each worksheet manually. Is there any way to have a Macro protect or unprotect multiple worksheets at once in Excel quickly and easily?
Protect All Worksheets At Once
Protect All Worksheets Use InputBox
'------------------ Modules ------------------
Sub ProtectAllWorksheetsWithInputbox()
'Step 1: Declare your variables
Dim ws As Worksheet
Dim Pwd As String
'Step 2: enter your password to protect all worksheets
Pwd = InputBox("Enter your password to protect all worksheets", "Password Input")
'Step 3: Start looping through all worksheets
For Each ws In ActiveWorkbook.Worksheets
'Step 4: Protect and loop to next worksheet
ws.Protect Password:=Pwd
Next ws
End Sub
Protect All Worksheets With Specific Password
'------------------ Modules ------------------
Sub ProtectAllWorksheets()
'Step 1: Declare your variables
Dim ws As Worksheet
'Step 2: Start looping through all worksheets
For Each ws In ActiveWorkbook.Worksheets
'Step 3: Protect all worksheets with specific password and loop to next worksheet
ws.Protect Password:="excel2013"
Next ws
End Sub
Unprotect All Worksheets At Once
Unprotect All Worksheets Use InputBox
'------------------ Modules ------------------
Sub UnProtectAllWorksheetsWithInputbox()
'Step 1: Declare your variables
Dim ws As Worksheet
Dim Pwd As String
'Step 2: enter your password to unprotect all worksheets
Pwd = InputBox("Enter your password to unprotect all worksheets", "Password Input")
On Error Resume Next
'Step 3: Start looping through all worksheets
For Each ws In Worksheets
'Step 4: Unprotect all worksheets and loop to next worksheet
ws.Unprotect Password:=Pwd
Next ws
'Step 5: Error handling
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
Unprotect All Worksheets With Specific Password
'------------------ Modules ------------------
Sub UnprotectAllWorksheets()
'Step 1: Declare your variables
Dim ws As Worksheet
'Step 2: Start looping through all worksheets
For Each ws In ActiveWorkbook.Worksheets
'Step 3: Unprotect all worksheets with specific password and loop to next worksheet
ws.Unprotect Password:="excel2013"
Next ws
End Sub
Unprotect Specific Worksheet With Specific Password
'------------------ Modules ------------------
Sub UnprotectSpecificWorksheet()
'Unprotect specific worksheet with specific password
Sheets("Sheet1").Unprotect Password:="excel2013"
Sheets("Sheet2").Unprotect Password:="excel2016"
Sheets("Sheet3").Unprotect Password:="excel2019"
Sheets("Sheet4").Unprotect Password:="excel2022"
End Sub
How to Use This Macro
Most VBA code should be placed in Standard Modules unless specified.
If you see a comment '------------------ Modules------------------
in the code header that means put the code in a Standard Module. For more information, learn this course: Where should I put the Excel VBA code?
The following steps teach you how to put VBA code into a Standard Module:
- Activate the Visual Basic Editor by pressing ALT + F11.
- Right-click the project/workbook name in the Project Window.
- Choose Insert -> Module.
- Type or paste the code in the newly created module. You will probably need to change the sheet name, the range address, and the save location.
- Click Run button on the Visual Basic Editor toolbar.
- For more information, learn this course: Programming with Excel VBA
OMG exactly what I have been looking for. Now I just need a macro that will list all tabs that have been unprotected.