vb code help

  • Thread starter Thread starter K-Man
  • Start date Start date
K

K-Man

Hi how do I edit following code for multiple worksheets?

Option Explicit
Sub auto_open()
With Worksheets("sheet1")
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
'.EnableAutoFilter = True
End With
End Sub

Thanks in advance..
 
Hi,

If you want to do it to all the sheets in the workbook


Private Sub Workbook_Open()
Dim sh As Worksheet
For Each sh In Worksheets
With sh
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
.EnableAutoFilter = True
End With
Next sh
End Sub

You are using the Auto_Open subroutine, instead you should consider using
the Workbook_Open()

This code goes into the thisWorkbook object in the VBA editior.

If this helps, please click the Yes button

Cheers,
Shane Devenshire
 
Hi,

If you want to do it to all the sheets in the workbook

Private Sub Workbook_Open()
Dim sh As Worksheet
For Each sh In Worksheets
With sh
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
.EnableAutoFilter = True
End With
Next sh
End Sub

You are using the Auto_Open subroutine, instead you should consider using
the Workbook_Open()

This code goes into the thisWorkbook object in the VBA editior.

If this helps, please click the Yes button

Cheers,
Shane Devenshire

Thanks Shane,

It works great for the job I want to do..Thanks very much for the
help..

Cheers,
 
Back
Top