Can I protect a range of worksheets in a book with one action?

G

Guest

If a workbook contains, say 20 worksheets, is there a way of
protecting/unprotecting all the sheets at the same time to avoid going into
each one separately to protect?
Using Office Excel 2003.
 
G

Guest

Use these 2 macros to protect and unprotect all sheets:

Sub ProtectAllSheets()
Dim ws As Worksheet
Dim strPassWord As String
strPassWord = "apple" '<--- set password here
For Each ws In ThisWorkbook.Worksheets
ws.Protect Password:=strPassWord
Next
End Sub

Sub UnprotectAllSheets()
Dim ws As Worksheet
Dim strPassWord As String
strPassWord = "apple" '<--- set password here
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password:=strPassWord
Next
End Sub

---
Put the code in a regular/standard module. If you've never worked with
macros before, see:

http://office.microsoft.com/en-us/assistance/HP052047111033.aspx

and

http://www.mcgimpsey.com/excel/modules.html

HTH
Jason
Atlanta, GA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top