protect and unprotect all sheets by a command button

uttamsaxena

Board Regular
Joined
Apr 22, 2003
Messages
182
I have a workbook with 10 sheets, which all are protected by the password(Tools>Protection>protect) . Users only feed data and any change in sheet is to be done by me every month. For editing something in each sheet, I have to protect and unprotect all sheets one by one.How can this be done by a command button on sheet one, which should ask for the password and on correct password shall unprotect all the sheets. Similarly another button on sheet 1 should lock all the sheets on confirmation of a password.

However for unprotecting and protecting single sheet, the normal method (Tools>Protection>unprotect) should do.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
uttamsaxena said:
I have a workbook with 10 sheets, which all are protected by the password(Tools>Protection>protect) . Users only feed data and any change in sheet is to be done by me every month. For editing something in each sheet, I have to protect and unprotect all sheets one by one.How can this be done by a command button on sheet one, which should ask for the password and on correct password shall unprotect all the sheets. Similarly another button on sheet 1 should lock all the sheets on confirmation of a password.

However for unprotecting and protecting single sheet, the normal method (Tools>Protection>unprotect) should do.

Private Sub CommandButton1_Click()
Dim ws As Worksheet
dim Password as string
Password = Inputbox "Password"
For Each ws In ActiveWorkbook.Worksheets
If ws.ProtectContents = True Then
ws.Unprotect Password
Else
ws.Protect Password
End If
Next
End Sub
 

Forum statistics

Threads
1,186,174
Messages
5,956,369
Members
438,249
Latest member
georgebasalic3

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
Top