run macro on opening

  • Thread starter brian thompson3001 via OfficeKB.com
  • Start date
B

brian thompson3001 via OfficeKB.com

Hi
(originally put in wrong grouping)

I have go this off other threads, but would like it to run automatically when
opening the workbook. I am not up to speed with these codes, and therefore
ask if the additional line/lines could be added in the correct place, in
order that I can copy and Paste. Currently, I have to run this every time
after opening the workbook

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

End Sub

Can anyone help?,

Brian
 
P

PCLIVE

You need your code in ThisWorkbook. Use this.

Private Sub Workbook_Open()
With Worksheets("sheet1")
Protect Password:="test", userinterfaceonly:=True
EnableAutoFilter = True
End With
End Sub

HTH,
Paul
 
D

Dave Peterson

Open the workbook.
Go to the VBE
Hit ctrl-r to see the project explorer
Find your workbook/project
click on it one time
Insert|Module

Paste the code there (and delete any copies of that code you placed elsewhere).

Alt-f11 to get back to excel
close that file (and save it while saving)
reopen that file (allowing macros to run)
 
B

brian thompson3001 via OfficeKB.com

hi paul/dave

have copied your code following Dave's instructions, however getting
"Compile error"
"named argument not found"

Any idea's

regards
You need your code in ThisWorkbook. Use this.

Private Sub Workbook_Open()
With Worksheets("sheet1")
Protect Password:="test", userinterfaceonly:=True
EnableAutoFilter = True
End With
End Sub

HTH,
Paul
Hi
(originally put in wrong grouping)
[quoted text clipped - 19 lines]
 
D

Dave Peterson

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

Watch those leading dots.



brian thompson3001 via OfficeKB.com said:
hi paul/dave

have copied your code following Dave's instructions, however getting
"Compile error"
"named argument not found"

Any idea's

regards
You need your code in ThisWorkbook. Use this.

Private Sub Workbook_Open()
With Worksheets("sheet1")
Protect Password:="test", userinterfaceonly:=True
EnableAutoFilter = True
End With
End Sub

HTH,
Paul
Hi
(originally put in wrong grouping)
[quoted text clipped - 19 lines]

--
bnt

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/ms-excel/200612/1
 
B

brian thompson3001 via OfficeKB.com

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