How to add delay of 5 seconds using vba?

Hi,

I am running few vba functions, sometimes the next functions is executed even before the previous function is complete.  So I thought I wold add a delay of 5 - 10 seconds after every function.

The below function is used in excel, could someone please let me know for the word vba.

Application.Wait(Now + TimeValue("0:00:01"))

Fo eg: I have two function to insert text, now the "Text2" should insert after 5 seconds of adding "Text1"

Selection.TypeText Text:="Text1"
Selection.TypeText Text:="Text2"


Regards,
Anand 
I managed to search the below code to add timer between two macros, but within a macro how do I add wait timer?

Application.OnTime When:=Now + TimeValue("00:00:05"), _
Name:="MyDelayMacro"

2 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub Doze(ByVal lngPeriod As Long)
DoEvents
Sleep lngPeriod
' Call it in desired location to sleep for 1 seconds like this:
' Doze 1000
End Sub

Sub Demo()
MsgBox "1"
Doze 3000
MsgBox "2"
End Sub

Greg Maxey
***
Death smiles at us all, but all a man can do is smile back.


For more help with Word visit:
http://gregmaxey.com/word_tips.html

5 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated March 30, 2025 Views 17,997 Applies to:
You’re invited to try Microsoft 365 for free