The following procedure schedules the execution of another procedure at a future time:
Sub CallInFuture()
Application.OnTime Now + TimeValue("00:00:05"), "ShowApplicationPath"
End Sub
Explanation:
- The method OnTime() of the Application object is called.
- This method is used to execute procedures at a specified future time.
- It requires two arguments: the time at which to run the procedure and the name of the procedure as a string enclosed in double quotes.
- The time can be specified either as an absolute time (e.g., 5:35:30 PM) or as a relative time offset.
- In Listing 6.15, a relative time is used: the current time obtained via the built-in Now() function is incremented by 5 seconds, which is represented using the TimeValue(« 00:00:05 ») function.
- Therefore, the procedure « ShowApplicationPath » will be executed 5 seconds after CallInFuture is run.