Author: Oscar Cronquist Article last updated on October 25, 2017

This article explains how to set up a workbook so a macro is rund every time you open the workbook. Excel event code makes this possible and it is easier than you think.

For example, you could have a macro that opens another workbook that you need, saving you time, making you happy and feeling awesome.

Create a macro

The following macro opens workbook Book1.xlsx in folder c:\temp

Sub Macro1
Workbooks.Open ("c:\temp\Book1.xlsx")
End Sub

Copy the macro code above and go to tab "Developer" on the ribbon. If it is missing search the internet for your Excel version and "Show developer tab".

Press with mouse on "Visual Basic" button to open the Visual Basic editor. Press with right mouse button on on your workbook in the Project Explorer window.

Press with mouse on "Insert" and then on "Module". This action adds a code module to your workbook.

Now paste the VBA code above to your code module.

Go back to Excel. Go to tab "Developer" and press with left mouse button on "Macro" button. The following dialog box appears:

Press with mouse on "Run" button and the workbook is opened.

The following article shows you how to open multiple excel files using checkboxes:

Open Excel files in a folder [VBA]

This tutorial shows you how to list excel files in a specific folder and create adjacent checkboxes, using VBA. The […]

Open Excel files in a folder [VBA]

How to run a Macro upon opening a workbook

Press Alt+F11 to open the VB Editor or go to tab "Developer" on the ribbon, press with left mouse button on "Visual Basic" button. Double press with left mouse button on "This Workbook", if you can't see it expand the list by press with left mouse button oning on the + sign.

Paste the following event code to the workbook module:

Private Sub Workbook_Open()
End Sub

Go back to Excel. Save the workbook with file extension *.xlsm, this is important.

Close workbook and open it again. The workbook Book1.xlsx in folder c:\temp is now automatically opened. (If it exists..)