Forum Discussion
nickii95
Mar 25, 2022Copper Contributor
VBA Protect and Unprotect for a specific sheet
Dear Community, This VBA allows me to protect and unprotect the workbook. However, I would prefer just a few sheets rather than the whole workbook. Sub ProtectWB_Protect_All_Sheets_Pswrd()
...
- Mar 25, 2022
Like this:
Sub ProtectWB_Protect_All_Sheets_Pswrd() ActiveWorkbook.Unprotect "password" Worksheets("a").Protect Paswword:="eren", DrawingObjects:=True, Contents:=True, Scenarios:=True Worksheets("b").Protect Paswword:="eren", DrawingObjects:=True, Contents:=True, Scenarios:=True Worksheets("c").Protect Paswword:="yeagar", DrawingObjects:=True, Contents:=True, Scenarios:=True ActiveWorkbook.Protect "password" End Sub
HansVogelaar
Mar 25, 2022MVP
Like this:
Sub ProtectWB_Protect_All_Sheets_Pswrd()
ActiveWorkbook.Unprotect "password"
Worksheets("a").Protect Paswword:="eren", DrawingObjects:=True, Contents:=True, Scenarios:=True
Worksheets("b").Protect Paswword:="eren", DrawingObjects:=True, Contents:=True, Scenarios:=True
Worksheets("c").Protect Paswword:="yeagar", DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveWorkbook.Protect "password"
End Sub