Run macro x minutes after opening workbook

JugglerJAF

Active Member
Joined
Feb 17, 2002
Messages
297
Office Version
  1. 365
Platform
  1. Windows
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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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
 
Upvote 0
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:
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,705
Members
449,048
Latest member
81jamesacct

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
Back
Top