This article explains how to set up a workbook so a macro is executed 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".

Click on "Visual Basic" button to open the Visual Basic editor. Right-click on your workbook in the Project Explorer window.

Click 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 click on "Macro" button. The following dialog box appears:

Click 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 specified folder and create adjacent checkboxes, using vba. The […]

Comments(38) Filed in category: Check-boxes, Excel, Files and folders

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, click on "Visual Basic" button. Double click on "This Workbook", if you can't see it expand the list by clicking on the + sign.

Paste the following event code to the workbook module:

Private Sub Workbook_Open()
Macro1
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..)