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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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:=InputBox("Enter password for " & Sheets(SheetsIndex(j)).Name)
Next j
End Sub
 
Upvote 0
Rich (BB code):
Sub SelectedSheetsProtect()

'VOG MrExcel

Dim ws As Worksheet
Dim SheetsIndex(1 To 100)
Dim i As Long, j As Long

pass = InputBox("Enter password")


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:=pass
Next j
End Sub


Sub SelectedSheetsUnprotect()

'VOG MrExcel

Dim ws As Worksheet
Dim SheetsIndex(1 To 100)
Dim i As Long, j As Long

pass = InputBox("Enter password")

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)).Unprotect Password:=pass
Next j
End Sub

Nice work... I moved the password to the top for those that have the same password for all sheets selected so you don't have to enter passwords for each sheet. But at least now the password isn't hard coded and you can use this for any workbook!

Thanks for the great code!
 
Upvote 0
Great stuff. Just be aware that if a user mis-types a password and can't get back in then we won't be able to help (forum rules).
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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