vb code help

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..
 
S

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
 
K

K-Man

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top