Can I Protect all Sheets at Once?

B

Brandon

I'm wanting to protect all sheets in a workbook so that users can't type in
locked cells. Is there a way to do all of the sheets at once instead of
going sheet by sheet? (and protecting a workbook is different)
 
D

Dave Peterson

You could use a macro...

Option Explicit
Sub testme()
Dim wks As Worksheet
Dim myPWD As String

myPWD = "hi"
For Each wks In ActiveWorkbook.Worksheets
wks.Protect Password:=myPWD
Next wks
End Sub
 
J

Jack Gillis

Excellent suggestion.

Can this 'For Each' technique be used for locking all the cells in
Worksheet? I think I might like to try it?

Thank you.
 
D

Dave Peterson

Locking all the cells and protecting the worksheet are actually two different
things. And you can get all the cells all at once.

Option Explicit
Sub testme()
Dim wks As Worksheet
Dim myPWD As String

myPWD = "hi"
For Each wks In ActiveWorkbook.Worksheets
wks.cells.locked = true '<-- added
wks.Protect Password:=myPWD
Next wks
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