_Application.OnTime Method

Starts a background timer that runs a macro at a specified time.

Namespace:  Microsoft.Office.Interop.Word
Assembly:  Microsoft.Office.Interop.Word (in Microsoft.Office.Interop.Word.dll)

Syntax

'Declaration
Sub OnTime ( _
    ByRef When As Object, _
    Name As String, _
    ByRef Tolerance As Object _
)
'Usage
Dim instance As _Application
Dim When As Object
Dim Name As String
Dim Tolerance As Object

instance.OnTime(When, Name, Tolerance)
void OnTime(
    ref Object When,
    string Name,
    ref Object Tolerance
)

Parameters

  • When
    Type: System.Object%
    Required Object. The time at which the macro is to be run. Can be a string that specifies a time (for example, "4:30 pm" or "16:30"), or it can be a serial number returned by a function such as TimeValue or TimeSerial (for example, TimeValue("2:30 pm") or TimeSerial(14, 30, 00)). You can also include the date (for example, "6/30 4:15 pm" or TimeValue("6/30 4:15 pm")).
    Use the sum of the return values of the Now function and either the TimeValue or TimeSerial function to set a timer to run a macro a specified amount of time after the statement is run. For example, use Now+TimeValue("00:05:30") to run a macro 5 minutes and 30 seconds after the statement is run.
  • Name
    Type: System.String
    Required String. The name of the macro to be run. Use the complete macro path to ensure that the correct macro is run (for example, "Project.Module1.Macro1"). For the macro to run, the document or template must be available both when the OnTime instruction is run and when the time specified by When arrives. For this reason, it's best to store the macro in Normal.dot or another global template that's loaded automatically.
  • Tolerance
    Type: System.Object%
    Optional Object. The maximum time (in seconds) that can elapse before a macro that wasn't run at the time specified by When is canceled. Macros may not always run at the specified time. For example, if a sort operation is under way or a dialog box is being displayed, the macro will be delayed until Word has completed the task. If this argument is 0 (zero) or omitted, the macro is run regardless of how much time has elapsed since the time specified by When.

Remarks

Microsoft Word can maintain only one background timer set by OnTime. If you start another timer before an existing timer runs, the existing timer is canceled.

See Also

Reference

_Application Interface

_Application Members

Microsoft.Office.Interop.Word Namespace