VBA selecting multiple sheets

Solved/Closed
discokiza - Aug 28, 2009 at 05:42 AM
 discokiza - Sep 1, 2009 at 03:14 AM
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

Excelguru Posts 261 Registration date Saturday April 11, 2009 Status Member Last seen June 21, 2011 307
Aug 29, 2009 at 07:08 AM
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
Tnx very much. It was so simple.
1