Automatically Run a Macro so Many Seconds, Minutes, or Hours After an Excel Workbook has been Opened

Add to Favorites
Author:
Run a macro after a certain amount of time has passed since the Excel workbook was opened. This means that you can set this macro to run another macro after the Excel workbook has been open for 10 seconds, 25 minutes, 1 hour, etc. This allows you to run times sensitive macros in Excel, such as time based warnings - i.e. "You have 15 minutes left for this test!" As it is now, this macro will run another macro 10 seconds after the Excel workbook that contains this macro is opened.

This macro only calls another macro in Excel. This means that you have to already have another macro which you need this macro to run at a set time length. Also, this workbook must go in the "ThisWorkbook" window for macros and not a module. In order for this macro to work, you must save and close and then reopen the workbook after this macro has been installed in the workbook. This is because this macro is triggered to run by the opening of the workbook in which it is contained.

This macro uses the Application.OnTime method in Excel. In order to modify the macro for your needs, just change Name_of_Macro to the name of the macro which you want to run. Make sure the name is exactly the same and include any require parameters for the other macro if that is needed.

Also, you need to setup the macro to run the other macro at the time interval that best suits your needs. To do this, simply change 00:00:10 in the macro below. As it is this macro will run another macro 10 seconds after the workbook is opened. The first set of zeros is for hours; the next set is for minutes; the last set if for seconds.

Where to install the macro:  ThisWorkbook

Excel Macro to Automatically Run a Macro so Many Seconds, Minutes, or Hours After an Excel Workbook has been Opened

Private Sub Workbook_Open()
'Runs a macro 10 seconds after Excel is opened

Application.OnTime Now + TimeValue("00:00:10"), "Name_of_Macro"

End Sub







Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Similar Content on TeachExcel
Automatically Run a Macro at a Certain Time - i.e. Run a Macro at 4:30PM every day
Macro: Automatically run an Excel macro at a certain time. This allows you to not have to worry a...
Run a Macro at Set Intervals in Excel
Tutorial: Run a macro every 30 seconds, 1 minute, 10 minutes, 1 hour, etc.; this method allows you t...
Run a Macro when a User Does Something in the Workbook in Excel
Tutorial: How to run a macro when a user does something within the Workbook in Excel, such as openi...
Run a Macro When a Specific Cell Changes in Excel
Tutorial: Run a macro in Excel when a specific cell is changed; this also covers when a cell within...
Run a Macro when a User Does Something in the Worksheet in Excel
Tutorial: How to run a macro when a user does something in the worksheet, everything from selecting ...
Automatically Run a Macro When a Workbook is Opened
Tutorial: How to make a macro run automatically after a workbook is opened and before anything els...


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.

Tutorial Details
Similar Content
Automatically Run a Macro at a Certain Time - i.e. Run a Macro at 4:30PM every day
Macro: Automatically run an Excel macro at a certain time. This allows you to not have to worry a...
Run a Macro at Set Intervals in Excel
Tutorial: Run a macro every 30 seconds, 1 minute, 10 minutes, 1 hour, etc.; this method allows you t...
Run a Macro when a User Does Something in the Workbook in Excel
Tutorial: How to run a macro when a user does something within the Workbook in Excel, such as openi...
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course