Solved

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

Posted on 2004-03-20
7
13,728 Views
Last Modified: 2012-06-21
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
Comment
Question by:dougshepard
7 Comments
 
LVL 22

Expert Comment

by:Dreamboat
ID: 10641779
0
 

Author Comment

by:dougshepard
ID: 10641794
I am so confused.  All of that to pause for one second?
0
 
LVL 80

Assisted Solution

by:byundt
byundt earned 249 total points
ID: 10641875
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 10641906
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 10641919
I deleted my lame comments. :) Shhh...
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 10642127
Lame comments?  You have that luxury Dreamboat ;)
0
 
LVL 24

Accepted Solution

by:
R_Rajesh earned 251 total points
ID: 10643344
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now