This article was co-authored by wikiHow staff writer, Darlene Antonelli, MA. Darlene Antonelli is a Technology Writer and Editor for wikiHow. Darlene has experience teaching college courses, writing technology-related articles, and working hands-on in the technology field. She earned an MA in Writing from Rowan University in 2012 and wrote her thesis on online communities and the personalities curated in such communities.
This article has been viewed 9,845 times.
Learn more...
This wikiHow will teach you how to run macros in Excel automatically when you open a specific workbook, or how to create a macro that opens all your workbooks when you open Excel. Before you start, make sure you have the developer tab showing on the editing ribbon.
Steps
Running a Macro Automatically for a Specific Workbook
-
1Make sure the Developer tab is displayed on your editing ribbon. If it isn't and you're using a Windows computer, go to the File tab and click Options > Customize ribbon. Under "Main tabs" check the box next to "Developer."
- If you're using a Mac, you'll be able to enable the developer tab by going to Excel > Preferences (the menu at the top of your screen) then clicking Ribbon & Toolbar. In the "Customize the Ribbon" category, click the "Developer" checkbox and click Save.
-
2Click the Developer tab and select Visual Basic.Advertisement
-
3Double-click your workbook from the panel on the left. You'll see it listed under "VBA Project," but if you don't see it, click to expand the "VBA Project" folder.
-
4Enter the following code:
Private Sub Workbook_Open() Put your Macro-code here End Sub
-
5Close the Visual Basic Editor. You don't have to click save or anything before closing the editor.
- The next time you open this workbook, the macro code you entered between the sub and end sub lines will run.[1]
Creating a Macro to Run Automatically When You Start Excel
-
1Make sure the Developer tab is displayed on your editing ribbon. If it isn't and you're using a Windows computer, go to the File tab and click Options > Customize ribbon. Under "Main tabs" check the box next to "Developer."
- If you're using a Mac, you'll be able to enable the developer tab by going to Excel > Preferences (the menu at the top of your screen) then clicking Ribbon & Toolbar. In the "Customize the Ribbon" category, click the "Developer" checkbox and click Save.
- This macro will open all the worksheets you want to open when you launch Excel, which is highly useful if you work on a few different projects each day.
-
2Click Record Macro. It's in the "Developer" tab in the "Code" grouping.
-
3Enter your macro name. Name it something like "Auto_Open" so you can read the title and know what it does.
-
4Click Personal Macro Workbook. You'll see this in the "Store macro in" box and will make the macro available every time you open Excel.
- You can fill out the description to remind you specifically of what this macro does.
-
5Click Ok. That window will close and every keystroke or button press will be recorded in the macro.
-
6Click the File and click Open. Your file manager will open.
-
7Select all the workbooks you want to open when you open Excel. If you need to select files in different locations, hold down Shift and click them.
-
8Click Stop Recording. All the keystrokes and button presses you made are recorded and stored in the macro.
-
9Close Excel. You'll be prompted to save the changes you've made, so click Yes and your macro will open all those workbooks whenever you restart Excel.
References
About This Article
1. Make sure the Developer tab is displayed on your editing ribbon.
2. Open VBA.
3. Double-click your workbook from the panel on the left.
4. Enter the displayed code.
5. Close the Visual Basic Editor.