Can I Protect all Sheets at Once?

  • Thread starter Thread starter Brandon
  • Start date Start date
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)
 
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
 
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.
 
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
 
Back
Top