0
Thanks

A few words of thanks would be greatly appreciated.

Excel VBA - Selecting multiple sheets




Issue


I have a certain VBA code that I use for group/ungroup on protected sheet. It works just fine but only on one sheet. How can I modify it to work on two?

Private Sub Workbook_open() 
With Sheet1 
.Protect Password:="secret", userinterfaceonly:=True 
.EnableOutlining = True 
End With 
End Sub 



I don't know how to add more than one sheet. Can somebody help me?

Solution


Try this:

Private Sub Workbook_open() 
With sheets("Sheet1 name") 
.Protect Password:="secret", userinterfaceonly:=True 
.EnableOutlining = True 
End With 
With sheets("Sheet2 name") 
.Protect Password:="secret", userinterfaceonly:=True 
.EnableOutlining = True 
End With 
End Sub

Note


Thanks to Excelguru for this tip on the forum.
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Related

This document, titled « Excel VBA - Selecting multiple sheets », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

0 Comments