How can I run a macro upon Excel file opening?

R

RKGriffin

I created an Excel Macro and I would like to have it run automatically when
the file is opened. How can I do this?
Thank you for the help. I have not been able to find the answer.

Sincerely
Robert Griffin
 
E

ehntd

You need to open the VB Editor. There you double click on This
Workbook. In there you add a sub:

Private Sub Workbook_Open()
´call your method here
End sub

This will execute every time you open the workbook
 
N

Nikos Yannacopoulos

Robert,

You need to palce your code in the Workbook _Open event. To do so:

* Right-click on a worksheet tab and select View Code
* When taken to the VB window, Locate object VBAProject(YourWorkbookName) in
the project explorer window on the left, and expand it if not already
expanded; double-click on This Workbook
* Locate the two drop-down boxes on top of the main window, and change the
one on the left from default (General) to Workbook; notice the two lines of
code that are automatically entered in the main window:

Private Sub Workbook_Open()

End Sub

Whatever code you put in between will be executed whenever you open the
workbook. You could either paste the code here, or leave it in the general
module where it currently is and just call it from here, like:
My_Macro_Name

HTH,
Nikos
 
D

Dave Peterson

If you've already got that macro in a General module, you could just rename it
to: Auto_open
 
Top