Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a Maro upon worksheet open.

Status
Not open for further replies.

jeff1

IS-IT--Management
Nov 8, 2000
49
US
I need to run a macro when a worksheet is opened. I have the macro written, I just can't find the option to run it when a particular worksheet is accessed.

Thank you in advance for your help
 
WorkSHEET or workBOOK ???
You can use the worksheet_activate event for a worksheet
Right click on the sheet tab and choose "View code"
then, change the right hand drop down to "Activate" and pop the name of the macro you want to run between the start and finish
...and delete the selection change event sub that will be automatically generated when you hit "View Code"

For workBOOK - use either the workbook_open event (go to VBE, double click on the "workbook" icon in your "projects" list) or create a sub called Auto_open in a standard module Rgds
Geoff

Si hoc legere scis, nimis eruditionis habes
 
Geoff,
I'm a bit hazy on the last method. I too have a spreadsheet/workbook that I'd like a macro to run when the spreadsheet is opened. The spreadsheet/workbook contains 3 worksheets. What do I need to do to get the macro to run.
Many thanks
Marc
 
Say you have a macro called
DoMyStuff
in a normal module

Go to the Visual Basic Editor and double click on "this workbook"

Select "Workbook" from the left hand drop down list. The workbook_open sub will appear automatically

the sub / end sub will be there automatically so you just need to add the line to call your macro

Private Sub Workbook_Open()
DoMyStuff
End Sub

HTH

Rgds
Geoff

Si hoc legere scis, nimis eruditionis habes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top