Making a macro pause for a few seconds

P

Peter Rooney

Can anyone tell me how to accomplish this, please?

Excel has a WAIT function, but Word doesn't seem to recognize it.

Thanks

Pete
 
J

Jonathan West

Peter Rooney said:
Can anyone tell me how to accomplish this, please?

Excel has a WAIT function, but Word doesn't seem to recognize it.


Put this statement before the first Sub or Function in any module

Public Declare Sub Sleep Lib "kernel32" _
Alias "Sleep" (ByVal dwMilliseconds As Long)

Then you can call it anywhere in your code like this

Sleep 100 'inserts a 100ms pause


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
H

Helmut Weber

Hi Peter,

Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds
As Long)

Or if you prefer something simple, not to say primitive:

Public Sub Wait(ByVal aNum As Integer)

Dim aTim As Single
aTim = Timer
While Timer < aTim + aNum
DoEvents
Wend
End Sub

I put a lot of effort in this,
if you need to wait for
10 days, 4 hours, 2 minutes, 4 seconds ;-)

ask again

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
G

Greg

Pete,

Not sure if this helps, but how about something like:

Sub Doze(ByVal lngPeriod As Long)
DoEvents
Sleep lngPeriod
' Call it in desired location to sleep for 10 seconds like this:
' Doze 10000
'Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long) must
'appear in the module level
End Sub
 
P

Peter Rooney

Thank you, Jonathan - this works fine!
Now all I need is a pointer to a good on-line downloadable Word VBA
reference -
any ideas?

Have a good weekend

Pete
 
P

Peter Rooney

Greg,

Thanks for this - it works fine, although I'm not sure I know why..! :))
I think I need a nice downloadable Word VBA reference to fully understand
ByVALs & stuff - any Ideas where I might find one?

Regards & have a good weekend

Pete
 
J

Jay Freedman

Hi Pete,

The entire VBA help system is on the MSDN web site, if you don't want to use
the one that's already installed on your computer. Start at
http://msdn.microsoft.com/library/en-us/off2000/html/wohowFrequentlyAsked.asp.
Use the left-hand navigation pane to find the rest of the topics.

Within the VBA editor, put the cursor on any keyword (such as ByVal) and
press F1 to open directly to the help topic about that word.

The Macros section of the FAQs at http://word.mvps.org is a good but
disorganized set of reference material. Try using the Search facility to
find topics that use the things you're interested in.
 
G

Greg

Pete,

LOL, You are not the only one stumbling along in darkness. I have
learned the little that I know about VBA by following this group and
asking lots of question. As time goes by you start to answer a few.
Hopefully one day I will understand the answers :). The Help in VBA
and the F1 key provides answers to lots of questions too. Good luck.
 
P

Peter Rooney

Cheers, Jay!

I may be old-fashioned, but I like a nice reference manual I can look at on
my desk, sometimes!

Thanks for your help - have a good weekend!

Pete
 
P

Peter Rooney

Greg,
I actually have helped a few people on Excel VBA and a couple on Project VBA
too- it's always a race to be the first and get the green tick, but it's good
when you do!

Thanks for your help

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top