is there any way I could add a text box on to my sheet and allow my users to type in a password and then click a button right next to the text box and have a code run which would take the enter password and unlock all pages on the workbooks at once?
You can do this, but a lot is going to depend on how much effort you want to put into hiding the password that unlocks the sheets, and re-installing the password once changes have been made.
This procedure will protect all of the sheets using the password that is contained in cell A1 of Sheet3:
Code:
Sub ProtectSheets()
Dim i As Integer
Dim strPassword As String
'Get the password from Sheet3 (which could be hidden or VeryHidden)
strPassword = Sheets("Sheet3").Range("A1").Value
'Protect all of the sheets
For i = 1 To Sheets.Count
Sheets(i).Protect Password:=strPassword
Next i
End Sub
Then, this procedure will unprotect all of the sheets if the TextBox (labeled as txtPassword) contains the right password. This would go in the code for the CommandButton (labeled as cmdEnterPassword):
Code:
Private Sub cmdEnterPassword_Click()
Dim i As Integer
Dim strPassword As String
strPassword = txtPassword.Value
If strPassword = Sheets("Sheet3").Range("A1").Value Then
For i = 1 To Sheets.Count
Sheets(i).Unprotect Password:=strPassword
Next i
End If
End Sub
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.