Premium Excel Course Now Available!
Build Professional - Unbreakable - Forms in Excel
45 Tutorials - 5+ Hours - Downloadable Excel Files
Instant Access! - Lifetime Access!
Automatically Run a Macro so Many Seconds, Minutes, or Hours After an Excel Workbook has been Opened
Add to Favorites
Favorited
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 - 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
()
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
- Select and copy the text from within the grey box above.
- Open the Microsoft Excel file in which you would like the Macro to function.
- Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.
Or For other ways to get there, Click Here.
For Excel Versions Prior to Excel 2007
Go to Tools > Macros > Visual Basic Editor
For Excel 2007
Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic
- 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.
- If the Macro goes in a Module, Click Here, otherwise continue to Step 8.
- Go to the menu at the top of the window and click Insert > Module
- Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
- Go to Step 8.
- If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Go to Step 8.
- If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
- Go to Step 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.
- You are now ready to run the macro.