Solved

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

Posted on 2004-03-20
7
14,886 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 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
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) …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

679 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