protect & unprotect sheets

K

Khalil Handal

Is there a way to protect and unprotect *multiple* sheets at once. All the
sheets have the same password (say 1234).
 
N

Nick Hodge

Khalil

You could use code like below, but cannot do it through the UI

Sub ProtectAll()
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
wks.Protect Password:="1234"
Next wks
End Sub

Sub UnProtectAll()
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
wks.Unprotect Password:="1234"
Next wks
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
web: www.nickhodge.co.uk
blog (non-tech): www.nickhodge.co.uk/blog/
 
G

Guest

If you have sheets within a workbook that are all password protected with
"secret", then this small macro will un-protect all at once:

Sub AtRisk()
MyPass = "secret"
For Each sh In Sheets
sh.Unprotect (MyPass)
Next
End Sub
 
K

Khalil Handal

Thank you both. It worked fine

Gary''s Student said:
If you have sheets within a workbook that are all password protected with
"secret", then this small macro will un-protect all at once:

Sub AtRisk()
MyPass = "secret"
For Each sh In Sheets
sh.Unprotect (MyPass)
Next
End Sub
 

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