Unprotect Sheets

brooklyn2007

Board Regular
Joined
Nov 20, 2010
Messages
143
Hello. I have many sheets in my workbook with protection, same password for all of them. When I need to make a change to all these sheets, i have to go over one by one to unprotect them in order to do the changes. Is there any way to unprotect at once all the selected sheets? Also, is there any way to protect at once all the selected sheets? Thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try like this

Code:
Sub ProtSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    ws.Protect Password:="abc"
Next ws
End Sub


Sub UnProtSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    ws.Unprotect Password:="abc"
Next ws
End Sub
 
Upvote 0
Try like this

Code:
Sub ProtSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    ws.Protect Password:="abc"
Next ws
End Sub


Sub UnProtSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    ws.Unprotect Password:="abc"
Next ws
End Sub

Thx a lot :)
 
Upvote 0
I love this but can there be one thing added? Is there a way to manually select the sheets you want protected/unprotected and have those sheets protected/unprotected only?

This does all the sheets in the workbook. There are sheets that are hidden and visible that I don't want protected/unprotected, etc.
 
Upvote 0
I love this but can there be one thing added? Is there a way to manually select the sheets you want protected/unprotected and have those sheets protected/unprotected only?

This does all the sheets in the workbook. There are sheets that are hidden and visible that I don't want protected/unprotected, etc.

Yep, select the sheets first then try like this

Code:
Sub ProtSheets()
Dim ws As Worksheet
For Each ws In ActiveWindow.SelectedSheets
    ws.Protect Password:="abc"
Next ws
End Sub
 
Upvote 0
USE:

Code:
Sub ProtSheets()
Dim wSHT as Object
For Each wSHT In ActiveWindow.SelectedSheets
    wSHT .Protect Password:="abc"
Next wSHT 
End Sub
Code:
Sub UnProtSheets()
Dim wSHT as Object
For Each wSHT In ActiveWindow.SelectedSheets
    wSHT .Unprotect Password:="abc"
Next wSHT 
End Sub
 
Upvote 0
USE:

Code:
Sub ProtSheets()
Dim wSHT as Object
For Each wSHT In ActiveWindow.SelectedSheets
    wSHT .Protect Password:="abc"
Next wSHT 
End Sub
Code:
Sub UnProtSheets()
Dim wSHT as Object
For Each wSHT In ActiveWindow.SelectedSheets
    wSHT .Unprotect Password:="abc"
Next wSHT 
End Sub

Drom: Same thing here error at wSHT.Unprotect Password:="abc" (as with protect password too).

also there was a space between wSHT and unprotect in orig code.

And yes, I changed the password to reflect my sheets password which all have the same pass.
 
Upvote 0
Not as easy as I thought :)

Try

Code:
Sub ProtSheets()
Dim ws As Worksheet
Dim SheetsIndex(1 To 100)
Dim i As Long, j As Long
For Each ws In ActiveWindow.SelectedSheets
    i = i + 1
    SheetsIndex(i) = ws.Index
Next ws
Sheets(SheetsIndex(1)).Select
For j = 1 To i
    Sheets(SheetsIndex(j)).Protect Password:="abc"
Next j
End Sub
 
Upvote 0
Not as easy as I thought :)

Try

Code:
Sub ProtSheets()
Dim ws As Worksheet
Dim SheetsIndex(1 To 100)
Dim i As Long, j As Long
For Each ws In ActiveWindow.SelectedSheets
    i = i + 1
    SheetsIndex(i) = ws.Index
Next ws
Sheets(SheetsIndex(1)).Select
For j = 1 To i
    Sheets(SheetsIndex(j)).Protect Password:="abc"
Next j
End Sub


Prefecto!

Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,144
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top