Question posted 2008 · +5 upvotes
I have around 25 worksheets in my workbook (Excel spreadsheet). Is there a way I can protect all the 25 worksheets in single click ? or this feature is not available and I will have to write a VBA code to accomplish this. I need very often to protect all sheets and unprotect all sheets and doing individually is time consuming
Accepted answer +11 upvotes
I don’t believe there’s a way to do it without using VBA. If you are interested in a VBA solution, here is the code:
Dim ws as Worksheet
Dim pwd as String
pwd = "" ' Put your password here
For Each ws In Worksheets
ws.Protect Password:=pwd
Next ws
Unprotecting is virtually the same:
Dim ws as Worksheet
Dim pwd as String
pwd = "" ' Put your password here
For Each ws In Worksheets
ws.Unprotect Password:=pwd
Next ws
2 code variants in this answer
- Variant 1 — 7 lines, starts with
Dim ws as Worksheet - Variant 2 — 7 lines, starts with
Dim ws as Worksheet
Top excel-vba Q&A (6)
- How to clear the entire array? +58 (2010)
- How to change Format of a Cell to Text using VBA +55 (2011)
- Download attachment from Outlook and Open in Excel +43 (2012)
- Can a VBA function in Excel return a range? +36 (2009)
- 2 Dimensional array from range +34 (2013)
- Hiding an Excel worksheet with VBA +33 (2009)
excel-vba solutions on this site
.