Time delay in VBA

N

Newbie

Hello,
How can I introduce a time delay (5 seconds for ex) in VBA Project ?
Thanks
 
J

John

Newbie said:
Hello,
How can I introduce a time delay (5 seconds for ex) in VBA Project ?
Thanks

Newbie,
What do you mean by time delay? Are you looking to delay execution of
the macro or do you want to insert a delay in a project task or tasks?

John
Project MVP
 
N

Newbie

Hello John,
I need to slow down the running macro during 5 seconds (temporisation?)
because the screen updating is too slow. There is a VBA function in Excel to
do that, but I don't know it in Project.
Thanks
 
R

Rod Gill

Screen updating should finish before your macro can continue. However to
delay 5 seconds try:

Sub Delay()
Dim Tim As Single
Tim = Timer
Do Until Timer - Tim > 5
DoEvents
Loop
End Sub

DoEvents tells VBA to go away and handle any events (such as screen updating
maybe) then come back and continue.
 
N

Newbie

Wonderful! Thanks!


Rod Gill said:
Screen updating should finish before your macro can continue. However to
delay 5 seconds try:

Sub Delay()
Dim Tim As Single
Tim = Timer
Do Until Timer - Tim > 5
DoEvents
Loop
End Sub

DoEvents tells VBA to go away and handle any events (such as screen updating
maybe) then come back and continue.

--

Rod Gill
Project MVP
Visit www.msproject-systems.com for Project Companion Tools and more
 
J

John

Newbie said:
Wonderful! Thanks!

Newbie,
I've got an even better approach. In all of my macros that export data
from Project to Excel I invoke the ScreenUpdating Property and set it to
false. The same property is available for Project. Graphic redraw is one
of the biggest waster of time when running a VBA procedure, and most of
the time the user doesn't really need the results until the macro is
finished anyway.

John
Project MVP
 
R

Ray McCoppin

A better way to do this is to use the Win32 API. Like this.

In the Declarations section of your module, include this:

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

Then in your Sub, use it like so:

Sleep 1000 ' to make your macro "sleep" for one second ( 1000 milliseconds )

--
Ray McCoppin

http://www.randsmanagement.com
Views Service Monitor
SRS gantt charts
 

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