Created
October 3, 2025 14:16
-
-
Save bradland/eef2500e1057929bc3c020f0175fc9bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub ProtectAllSheets() | |
Dim ws As Worksheet | |
Dim pwd As String | |
pwd = InputBox("Enter password:") | |
If pwd = "" Then | |
MsgBox "Password entry was canceled or left blank. Exiting macro." | |
Exit Sub | |
End If | |
On Error Resume Next | |
For Each ws In ActiveWorkbook.Worksheets | |
ws.Protect Password:=pwd | |
Next ws | |
On Error GoTo 0 | |
MsgBox "All sheets are now protected with the entered password." | |
End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub ProtectSelectedSheets() | |
Dim ws As Worksheet | |
Dim pwd As String | |
pwd = InputBox("Enter password:") | |
If pwd = "" Then | |
MsgBox "Password entry was canceled or left blank. Exiting macro." | |
Exit Sub | |
End If | |
On Error Resume Next | |
For Each ws In ActiveWorkbook.SelectedSheets | |
ws.Protect Password:=pwd | |
Next ws | |
On Error GoTo 0 | |
MsgBox "Selected sheets are now protected with the entered password." | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment