Run macro x minutes after opening workbook

JugglerJAF

Active Member
Joined
Feb 17, 2002
Messages
272
Is there any way of setting up a macro that is run automatically a specified number of minutes (say 10) after a workbook has been opened.

We have a number of files that are used by many different employees and some people forget to save and close the file before going to a meeting of on lunch, meaning that the file is then not available to other employees.

There is no need for anyone to be in the file for more than 10 minutes so after that time has elapsed I'd like to run a macro to save and close the file (for which I do have the code) - it's just getting it to run 10 minutes after opening the file that I can't figure out!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi

Sure is - include the following code in the ThisWorkbook module of the book concerned:

Code:
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:10:00"), "my_Procedure"
End Sub

In the above, replace my_procedure by the name of the macro you want to run (retain the double quotes though).

Best regards

Richard
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,454
Hello JugglerJAF,
What you want to do is use the OnTime command in vba.
There are other considerations to take into account when invoking this so a simple example of
what you've asked for may not be in your best interest. (Which would look something like this
by the way):
Code:
Private Sub Workbook_Open()
Application.OnTime Now + TimeSerial(0, 10, 0), "YourMacroNameHere"
End Sub

I (pretty strongly) recommend doing a search (in vba help and right here on the board) for the
terms: OnTime and TimeSerial to get better aquanted with the ups & downs involved with using
them.


[EDIT:]
Ahh, I see I took too long typing again. Good morning Richard! :biggrin:
 

Forum statistics

Threads
1,141,720
Messages
5,708,090
Members
421,545
Latest member
TWR

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top