Application.OnTime running only once?

sark666

Board Regular
Joined
Jul 30, 2009
Messages
169
I have the following sub in the ThisWorkbook section:

Code:
Private Sub Workbook_Open()
    Application.OnTime TimeValue("03:00:00"), "START_procedure"
    
End Sub

I want it to run every day at 3 am. But it's running only once.

Hmm, I think I see my problem, under the thisWorkbook it's under workbook and Open so obviously it's only excuting once upon opening. Should I just have it as (General) (Declarations) ?

Does an application.OnTime macro even need to be in ThisWorkbook section? I thought I had read in a tutorial to set it up like that but I may be mistaken.
 
The open code sets a timer in Excel to run your macro. Without that it wouldn't run (except manually).

When your macro runs it (invisibly to you) deletes the original timer then sets a new timer to run itself at a specified time. The next time it runs, the same thing happens. This repeats unless you cancel the timer (see the link) or close Excel.
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Code:
Sub test()
MsgBox "SEE"
Application.OnTime Now + TimeValue("00:00:05"), "test"
End Sub


Try this and you will be convinced. It will run every 5 secounds.
 
Upvote 0
Code:
Sub test()
MsgBox "SEE"
Application.OnTime Now + TimeValue("00:00:05"), "test"
End Sub


Try this and you will be convinced. It will run every 5 secounds.


hi Prajul,

does this also work if i want to run the macro serveral times a day, everyday ?
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,258
Members
452,901
Latest member
LisaGo

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