Group/ Un-group in Protected sheet not working Correctly

kcroft88

New Member
Joined
Jun 23, 2016
Messages
37
Hi, 2nd post of the day :)

I am using a macro to allow users to expand and close grouped columns when the sheet is protected, and its works fine UNTIL I save, close it and go back in. When back in the workbook is locked (that's what I want), but when I try to expand the grouped columns it says "you cannot use this command in a protected sheet....". If I then go into the macro, press play and go back to the sheet it then works fine in protected mode. is there an addition to my code to make it run automatically so it works as soon as the sheet is open?


Private Sub Workbook_Open()
With Worksheets("Master Sheet")
.Protect Password:="password", Userinterfaceonly:=True
.EnableOutlining = True
End With
End Sub

Thanks in advance,
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
That code needs to be in the ThisWorkbook module of the workbook so that it works automatically.
 
Upvote 0
Rather obvious now you point it out :) I have moved it and it works great now :)

For future reference for code to work automatically does it always need to be in ThisWorkbook module? or would that have worked where I had it if the top line was modified and merged with the one below?
 
Upvote 0
That code is a Workbook event, and must be in ThisWorkbook. Event routines related to a specific object need to be in the code module for that object - for example, Worksheet events like Worksheet_Change or Worksheet_Activate must be in the code module for the relevant worksheet.
 
Upvote 0

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

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