frostybear
New Member
- Joined
- Nov 30, 2023
- Messages
- 1
- Office Version
- 2016
- Platform
- Windows
Hi - I have a file that needs to be protected on multiple sheets but still allows for collapsing/uncollapsing grouped, filtering, inserting comments, formatting, etc. I have 2 sets of code that almost work, but one does everything except the grouping and the other does everything except the password protection. I'm going crazy!
Option 1:
This does everything I need EXCEPT the password protection piece which I could not figure out how to correctly incorporate into this:
Option 2:
This one does everything I need EXCEPT the ability to collapse/uncollapse grouped columns/rows:
Hopefully this is an easy fix to get everything I need - I am definitely not an expert on this Thank you!
Option 1:
This does everything I need EXCEPT the password protection piece which I could not figure out how to correctly incorporate into this:
VBA Code:
Private Sub Workbook_Open()
Dim wsh As Variant
For Each wsh In Worksheets(Array("sheet 1", "sheet 2"))
wsh.EnableOutlining = True
wsh.EnableAutoFilter = True
wsh.Protect UserInterfaceOnly:=True, _
AllowFormattingCells:=True, _
AllowFormattingColumns:=True, _
DrawingObjects:=False, _
Contents:=True
Next wsh
End Sub
Option 2:
This one does everything I need EXCEPT the ability to collapse/uncollapse grouped columns/rows:
VBA Code:
Sub ProtectSheets()
Dim wsh As Variant
For Each wsh In Worksheets(Array("sheet 1", "sheet2"))
wsh.Protect Password = "password"
wsh.EnableOutlining = True
wsh.EnableAutoFilter = True
wsh.Protect UserInterfaceOnly:=True, _
AllowFormattingCells:=True, _
AllowFormattingColumns:=True, _
DrawingObjects:=False, _
Contents:=True
Next wsh
End Sub
Hopefully this is an easy fix to get everything I need - I am definitely not an expert on this Thank you!