Friday, May 27, 2011

Protect or Unprotect All Worksheets in a Workbook

Every have those workbooks with a significant number of worksheets that need to be protected so you go through each one and protect the worksheet and then two days later find it necessary to go back through and unprotect each one of them?  Well here's some code I came a cross on the internet that you can use to speed up the process.

This macro will unprotect all the worksheets and the following macro will protect them all.  Copy and paste into your Personal workbook for use on any workbook that you have open.

If you're  unfamiliar with using the Personal workbook there was a post here back in April that will help you with it's use

I have another version of this code that will display a message box for the entry of a password when protecting or unprotecting the worksheets.  If you would like a copy of that code leave a comment here on the blog or email me at the office.


Sub Unprotect_All_Sheets()

Application.ScreenUpdating = False
Dim I As Long
 For I = 1 To Sheets.Count
    Sheets(I).Select
    ActiveSheet.Unprotect
 Next I
Application.ScreenUpdating = True 

End Sub



Sub Protect_All_Sheets()

Application.ScreenUpdating = False
Dim I As Long
 For I = 1 To Sheets.Count
    Sheets(I).Select
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFiltering:=True
    ActiveSheet.EnableSelection = xlUnlockedCells
Next I
Application.ScreenUpdating = True

End Sub

No comments:

Post a Comment