VBA to run Macro at a specific time

okcheung

New Member
Joined
Jan 1, 2005
Messages
22
Dear all,
I need a code to check the time now to run another procedures in a specific time (say 15:00, I need to run Auto_Update, and in 16:00, I need to run another called "Check_Data").
Anyone got the code so that I can make reference to?


Andrew
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You need to use:
Code:
Application.OnTime TimeValue("15:00:00"), "Auto_Update"
Application.OnTime TimeValue("16:00:00"), "Check_Data"

Put these lines in a seperate macro and run it straight away. Your code will fire at the selected times.
 
Upvote 0
Thanks Lewiy, but I need a code that will run automatically when the workbook is kept open. Any idea?
 
Upvote 0
If you put that code in the Workbook_Open event then it will trigger when you open the document. When it reaches the time specified, it will trigger your macros as you asked. All done automatically.
 
Upvote 0
Actually I will keep my workbook open and will not close, so how can i do that so it would check existing time with the specified time, and run the program if the time is matched?
 
Upvote 0
Something would have to trigger the code in the first place, you can only trigger by time within another Sub which would have to be started at some point. I’m not 100% sure but I think once you run it once and keep the workbook open at all times, it will continue to run every day at the desired time. So all you have to do is run the initial code once.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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