On UrbanPro

View My Profile       Proud to be a Teacher       Write a Review  

Monday, June 13, 2016

VBA code to Protect and Unprotect all Worksheets in Active Workbook

You can use below VBA codes to Protect and Unprotect all Worksheets In Active Workbook.

Password is used as "RED" (use password without quotes)

Code to Protect All Worksheets In Active Workbook.

Sub ProtectAllSheets()

'Step 1:  Declare your variables
    Dim ws As Worksheet

'Step 2: Start looping through all worksheets
    For Each ws In ActiveWorkbook.Worksheets

'Step 3:  Protect and loop to next worksheet
    ws.Protect Password:="RED"
    Next ws

End Sub


Code to Un-Protect All Worksheets In Active Workbook.


Sub UnprotectAllSheets()

'Step 1:  Declare your variables
    Dim ws As Worksheet

'Step 2: Start looping through all worksheets
    For Each ws In ActiveWorkbook.Worksheets

'Step 3:  Protect and loop to next worksheet
    ws.Unprotect Password:="RED"
    Next ws

End Sub

Popular Posts