Enabling Group outline protected worksheets

psamu

Active Member
Joined
Jan 3, 2007
Messages
462
I have multiple worksheets protected with password and has group columns . I have following code but not working, I dont know what is wrong, please help. Thanks

Private Sub Workbook_Open()
' Dim ws As Worksheet
'
' For Each ws In Worksheets
'
' Select Case UCase(ws.Name)
' Case "7", "9"
' With ws
' .Protect Password:="Test", UserInterfaceOnly:=True
' .EnableOutlining = True
' End With
' Case Else
' End Select
'
' Next ws
'
'End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Remove the apostrophes from the front of each line, and ensure that the code is in the ThisWorkbook module of your workbook.
 
Upvote 0
Thanks. Actually it was not commented out in excel, when that was not working I did that, then I copied. This code is placed in workbook module. But some reason it is not working
 
Upvote 0
It will only work for sheets called "7" and "9", if that's the problem?
 
Upvote 0
No still not working, but if I put below code in workbood module for one sheet it works fine, but I dont know how to add multiple sheet in the same code.

Private Sub Workbook_Open()
' With Worksheets("Income")
''With ActiveWorkbook
'.Protect Password:="test", UserInterfaceOnly:=True
'.EnableOutlining = True
''.EnableAutoFilter = True
'End With
'End Sub
 
Upvote 0
You need to replace the "7" and "9" with the names of the sheets you want to allow grouping on.
 
Upvote 0
Unless you post the actual code you tried I cannot assist you with why it doesn't work...
 
Upvote 0
I tried all three below below

Private Sub Workbook_Open()
Dim ws As Worksheet

For Each ws In Worksheets

Select Case UCase(ws.Name)
Case ("Sheet5"), ("Sheet6")
With ws
.Protect Password:="test", UserInterfaceOnly:=True
.EnableOutlining = True
End With
Case Else
End Select

Next ws

End Sub
--------------------------------
Private Sub Workbook_Open()
Dim ws As Worksheet

For Each ws In Worksheets

Select Case UCase(ws.Name)
Case ("Income"), ("Expense")
With ws
.Protect Password:="test", UserInterfaceOnly:=True
.EnableOutlining = True
End With
Case Else
End Select

Next ws

End Sub
---------------------
Private Sub Workbook_Open()
Dim ws As Worksheet

For Each ws In Worksheets

Select Case UCase(ws.Name)
Case "Income", "Expense"
With ws
.Protect Password:="test", UserInterfaceOnly:=True
.EnableOutlining = True
End With
Case Else
End Select

Next ws

End Sub
 
Upvote 0
You need to put the names in upper case due to the use of UCase:
Code:
Private Sub Workbook_Open()
Dim ws As Worksheet

For Each ws In Worksheets

Select Case UCase(ws.Name)
Case "INCOME", "EXPENSE"
With ws
.Protect Password:="test", UserInterfaceOnly:=True
.EnableOutlining = True
End With
Case Else
End Select

Next ws

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

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