Solved

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

Posted on 2004-03-20
7
15,481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 81

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

717 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