VBA selecting multiple sheets

Solved/Closed
Report
-
 discokiza -
Hello,

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 dont know how to add more than one sheet. Can somebody help me?

2 replies

Posts
261
Registration date
Saturday April 11, 2009
Status
Member
Last seen
June 21, 2011
307
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
4
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2821 users have said thank you to us this month

Tnx very much. It was so simple.