Sub Wait()
waitTime = 5
start = Timer
While Timer < start + waitTime
DoEvents
Wend
End Sub
This procedure waits five seconds.
Timer
is a func tion that re turns the num ber
of seconds since midnight (e.g., at 12:01
A.M.
,
Timer
will re turn 60).
waitTime
is a vari able used to tell how many seconds to wait (change the number 5 to any
number to have this pro cedure wait that number of seconds). At the beginning of
the pro cedure, the variable
start
is set to the current time in sec onds (as re -
turned by
Timer
). Next, we loop un til the cur rent time is less than the time we
started plus the
waitTime
(which is five seconds in our example). In side the
loop (be tween the
While
state ment and the
Wend
state ment), we run
DoEvents_._Be_careful!_If_you_make_a_mistake_(perhaps_you_set_the_waitTime'>DoEvents
.
This lets VBA check to see if anything else is hap pening, particularly things that
the user might do, such as hit the Es cape key or click on another button. If you
don’t want the user to do anything while you are waiting, leave out
DoEvents
.
Be careful! If you make a mistake (perhaps you set the
waitTime
to five mil -
lion seconds in stead of five seconds or you mistyped
Timer
in the
Do While
state -
ment), you could end up in an in finite loop, essentially freezing PowerPoint. If you
feel you must stop the user from do ing any thing while VBA waits, leave
DoEvents
in your pro cedure un til you are sure everything works. Once you are certain every-
thing works, delete the
DoEvents
line. This will allow you to stop your presenta-
tion by hit ting the Es cape key while you are still testing your pro cedure.
Before we con tinue, get a new PowerPoint pre sentation and type the
Do'stlaringiz bilan baham: |