OnTime Method

Applies To

Application Object.

Description

Schedules a procedure to run at a specified time in the future (either at a specific time of day or after a specific period has passed).

Syntax

object.OnTime(earliestTime, procedure, latestTime, schedule)

object

Required. The Application object.

earliestTime

Required. The time when you want this procedure to run.

procedure

Required. The name of the procedure to run.

latestTime

Optional. The latest time the procedure can be run. For example, if latestTime is set to earliestTime + 30 and Microsoft Excel is not in Ready, Copy, Cut, or Find mode at earliestTime because another procedure is running, Microsoft Excel will wait 30 seconds for the first procedure to complete. If Microsoft Excel is not in Ready mode within 30 seconds, the procedure will not run. If this argument is omitted, Microsoft Excel will wait until the procedure can be run.

schedule

Optional. False to clear a previously set OnTime procedure. True (or omitted) to schedule a new procedure.

Remarks

Use Now + TimeValue(time) to schedule something at a time after the current time. Use TimeValue(time) to schedule something at a specific time.

Example

This example runs my_Procedure 15 seconds from now.


Application.OnTime Now + TimeValue("00:00:15"), "my_Procedure"

This example runs my_Procedure at 5 P.M.


Application.OnTime TimeValue("17:00:00"), "my_Procedure"

This example cancels the OnTime setting from the previous example.


Application.OnTime TimeValue("17:00:00"), "my_Procedure",,False