Protected Sheet, lost functionality (collapse, expand)

andrea91

New Member
Joined
Apr 26, 2018
Messages
2
I’m trying to protect cells in my worksheet while maintaining the functionality of collapsing and expanding the worksheet. I’m working in Microsoft Excel 2013.
I’ve read that I need to run the following code:

Private Sub Workbook_Open()

Sheets("Sheet1").Protect Password:="", UserInterfaceOnly:=True
Sheets("Sheet1").EnableOutlining = True

End Sub
Where do I insert the code? I want to be able to have this functionality after I save, close and reopen the workbook. I don’t want to have to run the code every time. Any advice is helpful! New to this. Thank you.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
while maintaining the functionality of collapsing and expanding the worksheet

What is expanding and collapsing the worksheet mean?

If that code will do what you want (and I don't think it will), it would go in the workbook module.

Open the workbook. Alt+F11 (open VBA)...Ctrl+R (Project Explorer)...expand the dropdown by your workbook name...find "ThisWorkbook" in the "Microsoft Excel Objects" folder and double click....paste code in the white area to the right.
 
Last edited:
Upvote 0
The + / - button that allows you to hide or unhide cells. Unsure of what is it called but you are correct, the code did not work. -__-
 
Upvote 0
That code should work. It must be in the ThisWorkbook module of the workbook. Once it is there, save, close and reopen the workbook.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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