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.

Method 1
Method 1 of 2:

Running a Macro Automatically for a Specific Workbook

  1. 1
    Make 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.
  2. 2
    Click the Developer tab and select Visual Basic.
    Advertisement
  3. 3
    Double-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.
  4. 4
    Enter the following code:
    Private Sub Workbook_Open()
    
     Put your Macro-code here
    
    End Sub
    
  5. 5
    Close 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]
  6. Advertisement
Method 2
Method 2 of 2:

Creating a Macro to Run Automatically When You Start Excel

  1. 1
    Make 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.
  2. 2
    Click Record Macro. It's in the "Developer" tab in the "Code" grouping.
  3. 3
    Enter your macro name. Name it something like "Auto_Open" so you can read the title and know what it does.
  4. 4
    Click 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.
  5. 5
    Click Ok. That window will close and every keystroke or button press will be recorded in the macro.
  6. 6
    Click the File and click Open. Your file manager will open.
  7. 7
    Select 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.
  8. 8
    Click Stop Recording. All the keystrokes and button presses you made are recorded and stored in the macro.
  9. 9
    Close 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.
  10. Advertisement

About This Article

Darlene Antonelli, MA
Written by:
wikiHow Technology Writer
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.
How helpful is this?
Co-authors: 5
Updated: January 6, 2021
Views: 9,845
Categories: Spreadsheets
Article SummaryX

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.

Did this summary help you?
Advertisement