Atul Garg
Atul Garg

Reputation: 15

How to delay the call of a macro in VBA word?

I am working in VBA in word and I want to call my macro after every 2 secs Is there any way around?

Upvotes: 0

Views: 1213

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49453

When a document opens, or any other event of your choice, execute the following code which starts the routine using the Application.OnTime method:

alertTime = Now + TimeValue("00:02:00")
Application.OnTime alertTime, "EventMacro"

Then just have a VBA macro sub called EventMacro that will repeat it.

Public Sub EventMacro()
  
  '... Execute your actions here'
  
  alertTime = Now + TimeValue("00:02:00")
  Application.OnTime alertTime, "EventMacro"
End Sub

Upvotes: 0

Related Questions