Protect/unprotect ALL worksheets in workbook ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

-- Is it possible to protect/unprotect all worksheets in a workbook at once
instead of having to do each individually if the password is the same?

News Gal
 
The only way to do that is with some VBA code:

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


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
The only way is to use a macro to do this

Sub test()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
sh.Unprotect "ron"
Next sh
End Sub

Or
sh.Protect "ron"
 
This macro would do the trick

Sub Unprotect()

Dim wb As Workbook
Dim ws As Worksheet
Dim blnIsProtected As Boolean
Set wb = ActiveWorkbook

For Each ws In wb.Worksheets
ws.Unprotect "test"
Next ws

Set wb = Nothing
Set ws = Nothing

End Sub
 
I need to know how to protect the entire worksheet (all tabs within it) with
a click of a button; not sure what the last solution entails. Please help.

ers
 
Sub ProtectAllSheets()
Application.ScreenUpdating = False
Dim n As Single
For n = 1 To Sheets.Count
Sheets(n).Protect Password:="justme"
Next n
Application.ScreenUpdating = True
End Sub

Sub UnprotectAllSheets()
Application.ScreenUpdating = False
Dim n As Single
For n = 1 To Sheets.Count
Sheets(n).Unprotect Password:="justme"
Next n
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP
 
Back
Top