Expanding and collapsing subtotal groups in a protected spreadsheet

Nederbrakel

New Member
Joined
Jan 23, 2019
Messages
11
I have a protected spreadsheet (without password) that has subtotals and the associated group levels. These cannot be expanded or collapsed when the sheet is protected.
I have found threads that deal with this and advise the following solution:
In the code for the sheet, put the following:

[FONT=&quot]Private Sub Workbook_Open()[/FONT]
[FONT=&quot] With Worksheets("IRS_Fixed") 'use correct sheet name[/FONT]
[FONT=&quot] .EnableOutlining = True[/FONT]
[FONT=&quot] .Protect UserInterfaceOnly:=True[/FONT]
[FONT=&quot] End With[/FONT]
[FONT=&quot]End Sub

I have tried this but it does nothing. I'm using Excel 2013.
Any advice?[/FONT]
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
The solution you are using is working fine for me (Office 365).
Is it possible that other code locks the sheet differently after the workbook is opened?

Can you try to confirm that this solution doesn't work but manually through the immediate window after executing these:
Code:
[COLOR=#000000] Worksheets("IRS_Fixed")[/COLOR][COLOR=#000000].EnableOutlining = True
[/COLOR][COLOR=#000000]Worksheets("IRS_Fixed")[/COLOR][COLOR=#000000].Unprotect [/COLOR]
[COLOR=#000000]Worksheets("IRS_Fixed")[/COLOR][COLOR=#000000].Protect UserInterfaceOnly:=True[/COLOR]
Check if collapsing/expanding works immediately after executing these lines.
The order of execution doesn't matter.
The unprotect is not really necessary, but just in case.
 
Last edited:
Upvote 0
It does not work.
This is what I get:
?Worksheets("IRS_Fixed").Unprotect
True
?Worksheets("IRS_Fixed").EnableOutlining = True
False
?Worksheets("IRS_Fixed").Protect UserInterfaceOnly:=True

After executing the last line, I get an error popup: Compile error: Expected: expression

I also have the following code attached to the sheet:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 2 And Target.Row > 23 Then
Cancel = True
Call addRow
End If
End Sub
 
Upvote 0
Sorry, remove the question marks.
These are requesting the values - not instructing a change.

And I see that you also have ADDROW procedure and maybe more.
ADDROW probably Unprotects the sheet, then protects it but not the way you need it.
Inspect all your - especially where you are protecting sheets.
 
Upvote 0
Sorry about the ? in the immediate window. I haven't used it before. It's a great tool.
Meanwhile I have found my mistake. I put the code:
Private Sub Workbook_Open()
Worksheets("IRS_Fixed").Unprotect
Worksheets("IRS_Fixed").EnableOutlining = True
Worksheets("IRS_Fixed").Protect UserInterfaceOnly:=True
End Sub
In the worksheet code instead of the ThisWorkbook code.

All seems to work fine now. Sorry about this mistake and thanks for pointing out the immediate window to me :).
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

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.
Go back
Back
Top