How to protect and unprotect multiple worksheets effeciently

G

Guest

In Excel 2003, I am trying to protect up to 20 worksheets in one workbook. I
then need to unprotect them to edit each sheet, then protect them again to
prevent editing. I spend half my life protecting and unprotecting! How may I
do this more effeciently?
 
G

Guest

Try something like this...

Sub ProtectAll()
Dim wks as worksheet

On error Resume Next
for each wks in Worksheets
wks.Protect Password:="tada"
next wks
On error Goto 0
end sub

Sub UnprotectAll()
Dim wks as worksheet

On error Resume Next
for each wks in Worksheets
wks.Unprotect Password:="tada"
next wks
On error Goto 0
end sub
 
P

Paul B

SumKnight, you can use a macro like this,

Sub Protect_All_Sheets()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets

ws.Protect password:="123"

Next ws

End Sub



Sub Unprotect_All_Sheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect password:="123"
Next ws
End Sub


To put in this macro, from your workbook right-click the workbook's icon and
pick View Code. This icon is at the top-left of the spreadsheet this will
open the VBA editor, in Project Explorer click on your workbook name, if you
don't see it press CTRL + r to open the Project Explorer, then go to insert,
module, and paste the code in the window that opens on the right hand side,
press Alt and Q to close this window and go back to your workbook and press
alt and F8, this will bring up a box to pick the Macro from, click on the
Macro name to run it. If you are using excel 2000 or newer you may have to
change the macro security settings to get the macro to run. To change the
security settings go to tools, macro, security, security level and set it to
medium


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003
 
G

Guest

Thanks for the quick and useful response. I have already implemented your
technique and am saving time.
 
G

Guest

Thank you so much for the perfect answer! I am saving hours at my work
beginning today, and looking so smart!

Mike Smith
(SumKnight)
 

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