Expand/Collapse in Worksheet not protected by VBA

gubertu

Board Regular
Joined
May 24, 2015
Messages
148
Hi all,

I need to protect a sheet and let the user to expand and collapse rows and columns.

I also need to save this WB in .xlsx (not in .xlsm) so I cannot use macros (as far as I know).

Is there a way to protect the sheet by the option Review/Protect sheet and let the user expand and collapse (same as EnableOutlining = True in VBA)?

Appreciate your help!

Thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Yes, there is. If you do not plan to protect/unprotect frequently you wouldn't need a macro so no problem to stay XLSX.
Set up the outlining as you need it. Protect the sheet as you like with all necessary settings.
While the sheet is active go to VB Editor (Alt+F11), then go to Immediate window (Ctrl+G), type these two lines and press Enter after each of them, then save the file:
Code:
ActiveSheet.EnableOutlining = True
ActiveSheet.Protect UserInterfaceOnly:=True
The first is just in case.
The second allows you to use outlining on a protected sheet. These setting will not change by itself so you shouldn't need to do it after further unprotect /protect operations on this sheet.
 
Upvote 0
Many thanks for your help.

I did what you proposed and It worked well, but when I close and reopen the book (saved in .xlsx), I cannot expand and collapse.

Probably with your code I could work with my protected file in .xlsx and expand and collapse, but I think I´m missing something...

Thanks!
 
Upvote 0
Sorry - you are right. These settings need updating on opening.
Well, one way is use XLSM (or XLSB or simply XLS if possible) file type and change the settings for the sheet when the Wb is opened.
There is another way though: you can create an add-in file to be loaded in the background, and it will change the settings, when this Wb is opened.
Code for detecting opening of another Wb can be found here: https://www.jkp-ads.com/articles/FixLinks2UDF01.asp
 
Last edited:
Upvote 0
Sorry for answering so late.

Finnaly I have dediced to save the fie in .xlsm and insert in my protecting code "EnableOutlining = True ".

Thanks for your time!
 
Upvote 0

Forum statistics

Threads
1,223,710
Messages
6,174,017
Members
452,542
Latest member
Bricklin

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