Allow users to click"+" to group/ungroup in a protected sheet - VBA

Jaspal

New Member
Joined
Jun 4, 2010
Messages
40
Hello there,

I have two public macro's to protect and unprotect my sheet, which I use in other macros using "Call". I want users to be able to click "+" to group/ungroup columns and rows.
Public Sub UnprotectSheet(sWhichSheet)
' This MAcro unprotects the sheet
If Sheets(sWhichSheet).ProtectContents = True Then
Sheets(sWhichSheet).Unprotect Password:=sProtectionPassword
End If
End Sub


Public Sub ProtectSheet(sWhichSheet)
' This Macro protects the Sheet
If Sheets(sWhichSheet).ProtectContents = False Then
Sheets(sWhichSheet).Protect Password:=sProtectionPassword, DrawingObjects:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True, AllowDeletingRows:= _
True
End If
End Sub




I tried using the below code in the Workbook_open, but it does not work. I get an error message that to group/ungroup i need to unprotect my sheet. I have also checked "Enable AutoFilter" in the protect worksheet option.

Private Sub Workbook_Open()
With Worksheets(Detailed)
.Protect Password:="protect", UserInterfaceOnly:=True
.EnableOutlining = True
End With
End Sub

I also tried, but it does not work either
Private Sub Workbook_Open()
With Worksheets("Detailed")
Call UnprotectSheet(ActiveSheet.Name)
.Protect Password:="protect", UserInterfaceOnly:=True
.EnableOutlining = True
End With
Call ProtectSheet(ActiveSheet.Name)
End Sub



Thank you in advance for help.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hello
This worked for me with Excel 2007. What version are you using?

Code:
' this example goes at a regular module


Sub OutL()


With Worksheets("Detailed")
    .Protect Password:="protect", UserInterfaceOnly:=True
    .EnableOutlining = True
End With


End Sub
 
Upvote 0

Forum statistics

Threads
1,221,472
Messages
6,160,040
Members
451,612
Latest member
ShelleyB55

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