by Allen Wyatt
(last updated July 23, 2016)
Andre has a workbook that contains 52 worksheets. He would like to protect the worksheets, but not the workbook itself. Currently he individually protects all 52 sheets. He wonders if there is a way to protect them all in one go.
The only way to do this is to use a macro. Fortunately, the macro is quite short:
Sub ProtectAllSheets() Dim ws As Worksheet For Each ws In Worksheets ws.Protect Next End Sub
When you run this macro, all of the worksheets in the workbook are protected, without specifying a password. (This means anyone can easily unprotect them.) If you want to specify a password, then you can do so with an easy modification:
Sub ProtectAllSheets() Dim ws As Worksheet For Each ws In Worksheets ws.Protect Password:="MyPassword" Next End Sub
The password you specify will be used for each of the worksheets, meaning that all of them will use the same password.
You can easily modify these macros to unprotect all your worksheets by simply changing the .Protect method to .Unprotect.
You should also be aware that if your workbook or worksheets utilize some options that preclude worksheet protection (such as sharing), then the macros will generate an error.
An entirely different approach is to use a third-party utility to do the protecting. You can find such utilities with a quick Internet search; an example would be Asap Utilities (http://www.asap-utilities.com).
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7511) applies to Microsoft Excel 2007, 2010, 2013, and 2016.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
When you share a protected workbook with other people, you may not want them to get around the protection by creating a ...Discover More
Want to hide certain columns within a worksheet so the contents are not visible to others? The answer lies in formatting ...Discover More
You can protect various parts of your worksheets by using the tools built into Excel. One thing you can protect is the ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.