VBA EXPERTS needed

berthuib

New Member
Joined
Jun 14, 2015
Messages
19
Dear VBA Experts,

What I need is: Enable outlining and use of filters on multiple protected sheets with password (it should not be the complete workbook).

I am completely new with VBA and the VBA codes below I found via google. I searched my problem via google too, but I can't find the right COMLETE answer. I hope you can help me.

The code below works perfect, but this code is for all sheets. I only want it for a few sheets.
Code:
 Private Sub Workbook_Open()
 For Each Sheet In Worksheets
 Sheet.Unprotect Password:="User2015"
 Sheet.EnableOutlining = True
 Sheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowSorting:=True, AllowFiltering:=True, _
 Password:="User2015", UserInterfaceOnly:=True
 Next
 End Sub
I only want to do it for a few sheets. So I tried the following.. but I get an error at the row where I added "(Array...)".
Code:
 Private Sub Workbook_Open()
 For Each Sheet In Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
 Sheet.Unprotect Password:="User2015"
 Sheet.EnableOutlining = True
 Sheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowSorting:=True, AllowFiltering:=True, _
 Password:="User2015", UserInterfaceOnly:=True
 Next
 End Sub
Can someone please help?

Thanks in advance!
 
Last edited by a moderator:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
What error did you get?
 
Upvote 0
Wow.. serious :/.. I'm feeling kind of stupid right now. I copied the second VBA code into my excel file again to be able to tell you what error I get... Aaaaanddd.. yes.. it worked perfectly without any error xD. So I have no idea wht I did wrong the other time. But i'm glad it works.

Thanks anyway!
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,338
Members
448,569
Latest member
Honeymonster123

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