Finance

Charts

Statistics

Macros

Search

Calling a Procedure with a Time Delay In Excel VBA

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.
0 0 votes
Évaluation de l'article
S’abonner
Notification pour
guest
0 Commentaires
Le plus ancien
Le plus récent Le plus populaire
Online comments
Show all comments
Facebook
Twitter
LinkedIn
WhatsApp
Email
Print
0
We’d love to hear your thoughts — please leave a commentx