Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 17291
  • Last Modified:

How do I pause or wait or sleep in VBA for Word?

In VBScript I use "Wscript.Sleep 1000" to pause my script for 1 second.  How do I do the same thing in VBA for Word?

Thanks
0
dougshepard
Asked:
dougshepard
2 Solutions
 
dougshepardAuthor Commented:
I am so confused.  All of that to pause for one second?
0
 
byundtCommented:
Hi dougshepard,
Word has both the Timer function and OnTime methods available for use.

From the on-line help for the Timer function:
This example uses the Timer function to pause the application. The example also uses DoEvents to yield to other processes during the pause.

Dim PauseTime, Start, Finish, TotalTime
If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then    'You can just set PauseTime to 1 if you don't want a message box
    PauseTime = 5    ' Set duration.
    Start = Timer    ' Set start time.
    Do While Timer < Start + PauseTime
        DoEvents    ' Yield to other processes.
    Loop
    Finish = Timer    ' Set end time.
    TotalTime = Finish - Start    ' Calculate total time.
    MsgBox "Paused for " & TotalTime & " seconds"
Else
    End
End If

The OnTime method schedules a macro to run at a certain time. It can be set up to run at constant intervals by merely resetting the alarm time for the next run. It is also discussed in Word's on-line help, but a better description is given (for Excel) by Chip Pearson at: http://www.cpearson.com/excel/ontime.htm

Cheers!

Brad
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Joanne M. OrzechManager, Document Services CenterCommented:
0
 
DreamboatCommented:
I deleted my lame comments. :) Shhh...
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
Lame comments?  You have that luxury Dreamboat ;)
0
 
R_RajeshCommented:
Your could also try the sleep funciton

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub mySub()
.
.
Sleep 1000 'pause for 1 second
.
.
End Sub

Rajesh
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now