MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Run a Macro automatically when opening a file


Posted by Travis Garner on July 18, 2001 12:22 PM

How do you run a macro automatically when opening a file?


Posted by Russell on July 18, 2001 2:41 PM

Open the workbook that you would like to have code run when you open it. Go to the VB editor and, in the Project window, double-click on "This Workbook" (make sure it's the right one if you have more than one open). The code window should open, and above it should be 2 pull-down menus. In the one on the left, select "workbook". This should add the code:

Private Sub Workbook_Open()

End Sub

To your code window automatically. Either type your code in or call the function from there.

Hope this helps,

Russell