Excel VBA: Efficiently Protect and Unprotect Multiple Worksheets at Once
Excel VBA: Efficiently Protect and Unprotect Multiple Worksheets at Once

Written By: Ada Codewell – AI Specialist & Software Engineer at Gray Technical
The Problem with Protecting and Unprotecting Sheets in Excel
If you work extensively with Excel, chances are that you’ve encountered the need to protect or unprotect multiple worksheets simultaneously. This is especially true for large files containing many sheets (e.g., 100+). Manually protecting/unprotecting each sheet can be tedious and time-consuming.
While manual methods work for small-scale tasks, they quickly become impractical when dealing with a larger number of worksheets. Fortunately, VBA macros provide an efficient solution to this problem by automating the process.
The Root Cause: Manual Management is Inefficient
Manually protecting or unprotecting each worksheet individually can be error-prone and inefficient for several reasons:
- Time Consuming: Clicking through each sheet to set protection takes a lot of time.
- Error-Prone: It’s easy to miss one or more sheets, leaving your data vulnerable.
- Lack of Consistency: Manual processes can lead to inconsistencies in how each sheet is protected (e.g., different passwords).
A Step-by-Step Solution: Using VBA Macros for Sheet Protection/Unprotection
Using a VBA macro to protect or unprotect all worksheets in an Excel workbook is straightforward. Below, I’ll walk you through the process of creating and running such macros.
Step 1: Open the Visual Basic Editor (VBE)
- Press Alt + F11: This will open the VBA editor in Excel.
- Insert a New Module: In the VBE, go to Insert > Module. A new module window should appear where you can write your code.
Step 2: Write Your Protection/Unprotection Macros
The following VBA macros will protect and unprotect all sheets in a workbook:
Sub ProtectAllSheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If Not ws.ProtectContents Then ' Check if sheet is not already protected
ws.Protect Password:="yourpassword", UserInterfaceOnly:=True
End If
Next ws
End Sub
Sub UnprotectAllSheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.ProtectContents Then ' Check if sheet is protected
ws.Unprotect Password:="yourpassword"
End If
Next ws
End Sub
Replace “yourpassword” with the password you want to use for protecting/unprotecting sheets.
Step 3: Run Your Macros
- Close VBE and return to Excel:: Press Alt + F11 again or click on the Excel icon in your taskbar.
- Run the Macro: Press Alt + F8, select either ProtectAllSheets or UnprotectAllSheets from the list of macros, then press Run.
A Practical Example: Using Macros for a Large Workbook with 100+ Sheets
Let’s say you have an Excel workbook containing over 100 sheets named sequentially (e.g., Sheet1, Sheet2,…Sheet100). You want to protect all these sheets using the same password.
Step-by-Step Implementation:
- Open your large workbook in Excel
- Press Alt + F11 to open VBE
- Insert a new module (Insert > Module)
- Copy and paste the ProtectAllSheets macro into your module window:
Sub ProtectAllSheets() Dim ws As Worksheet For Each ws In ThisWorkbook.Worksheets If Not ws.ProtectContents Then ' Check if sheet is not already protected ws.Protect Password:="yourpassword", UserInterfaceOnly:=True End If Next ws End SubReplace “yourpassword” with your desired password.
- Close VBE and return to Excel (Alt + F11)
- Run the macro: Press Alt + F8, select ProtectAllSheets from the list of macros, then press Run. All sheets will be protected with your specified password.
A Practical Example: Using Macros for a Large Workbook with 100+ Sheets (Unprotect)
Now let’s say you need to unprotect all these sheets using the same macro approach:
- Open your large workbook in Excel
- Press Alt + F11 to open VBE
- Insert a new module (if not already done) or use the existing one:
Sub UnprotectAllSheets() Dim ws As Worksheet For Each ws In ThisWorkbook.Worksheets If ws.ProtectContents Then ' Check if sheet is protected ws.Unprotect Password:="yourpassword" End If Next ws End SubReplace “yourpassword” with the password you used for protecting sheets.
- Close VBE and return to Excel (Alt + F11)
- Run the macro: Press Alt + F8, select UnprotectAllSheets from the list of macros, then press Run. All protected sheets will be unprotected.
The Advanced Variation: Conditional Protection/Unprotection Based on Sheet Names or Content
In some cases, you may want to protect/unprotect only specific worksheets based on their names or content:
Sub ProtectSpecificSheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If Not ws.ProtectContents And Left(ws.Name, 5) = "Sheet" Then ' Only protect sheets starting with "Sheet"
ws.Protect Password:="yourpassword", UserInterfaceOnly:=True
End If
Next ws
End Sub
Sub UnprotectSpecificSheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.ProtectContents And Left(ws.Name, 5) = "Sheet" Then ' Only unprotect sheets starting with "Sheet"
ws.Unprotect Password:="yourpassword"
End If
Next ws
End Sub
This example protects/unprotects only those worksheets whose names start with the word “Sheet”. You can customize this condition based on your specific requirements.
Common Mistakes and Misconceptions When Working With VBA Macros for Sheet Protection/Unprotection
- Incorrect Password:: Ensure you use the same password when unprotecting sheets as used during protection. A mismatch will result in an error.
- UserInterfaceOnly Parameter:: When protecting, using UserInterfaceOnly:=True allows users to select cells for formatting but not edit content – a useful feature often overlooked.
The Role of Tools Like CelTools in Enhancing Productivity:
While you can manually write and execute VBA macros, tools like CelTools offer additional features for auditing, formulas, and automation that complement your workflow. For example, CelTools provides 70+ extra Excel features designed to streamline tasks such as protecting/unprotecting multiple sheets.
A Technical Summary: Combining Manual Techniques with Specialized Tools
In this article, we’ve covered how to efficiently protect and unprotect all worksheets in an Excel workbook using VBA macros. This approach is particularly useful for large workbooks containing many sheets (100+). By automating the process through VBA, you can save time and reduce errors associated with manual management.
Additionally, tools like CelTools offer enhanced features that complement your workflow by providing additional automation capabilities beyond basic Excel functionality. Combining these specialized tools with a solid understanding of VBA macros allows for even greater efficiency in managing large-scale Excel projects.






















