tlc53
Active Member
- Joined
- Jul 26, 2018
- Messages
- 399
Hi,
I found this neat VBA code to protect / unprotect all worksheets without having to do each one manually. See below. The only problem is, it only allows;
- Select Locked Cells
- Select Unlocked Cells
Whereas I want another 2 options to be included as well;
- Format columns
- Format rows
Does anyone know how I can add these two options into the code below? I tried adding the below under the password;
AllowFormattingColumns:=True, _
AllowFormattingRows:=True
But it returned a Compile Error.
Thank you.
I found this neat VBA code to protect / unprotect all worksheets without having to do each one manually. See below. The only problem is, it only allows;
- Select Locked Cells
- Select Unlocked Cells
Whereas I want another 2 options to be included as well;
- Format columns
- Format rows
Does anyone know how I can add these two options into the code below? I tried adding the below under the password;
AllowFormattingColumns:=True, _
AllowFormattingRows:=True
But it returned a Compile Error.
Thank you.
Code:
Sub ProtectAll()
'Step 1: Declare your variables
Dim ws As Worksheet
'Step 2: Start looping through all worksheets
For Each ws In ActiveWorkbook.Worksheets
'Step 3: Protect all worksheets with specific password and loop to next worksheet
ws.Protect Password:="password"
Next ws
End Sub
Sub UnprotectAll()
'Step 1: Declare your variables
Dim ws As Worksheet
'Step 2: Start looping through all worksheets
For Each ws In ActiveWorkbook.Worksheets
'Step 3: Unprotect all worksheets with specific password and loop to next worksheet
ws.Unprotect Password:="password"
Next ws
End Sub