p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

vba_excel thread: How to make the Timer?

Message #1 by "Bomin Kim" <kbm2002@s...> on Mon, 7 Jan 2002 13:58:26

If you are just trying to make something happen sometime in the future, you
can use the 'Time' method.

For example, insert the following code into a new module:

Option Explicit

Sub SayHello()

    MsgBox "Hello!"

End Sub

Sub SetTimer()

    Application.OnTime Now() + TimeValue("00:00:10"), "SayHello"

End Sub

Run the sub 'SetTimer()' subroutine and you will get a messagebox saying
'Hello' in 10 seconds time.

I'm not sure if this works for excel '97 and previous.


"Bomin Kim" <kbm2002@s...> wrote in message
> I have written the timer which runs repeatedly as follow until EndTime.
> By modifying the number ,that is 9000000, I can control the time period.
> As u might be aware of it, to achieve it, the system has to be working
> continuously(for looping), so that it proetcts other procedures from
> working.
> Pls teach me how to make an awesome timer, which actually runs at the
> specific time and pause for the rest of period.
> Thanks.
> ---------------------------
>  Dim EndTime, CurTime, i
>    CurTime = Format(Now, "hh:mm:ss")
>    EndTime = "24:00:00"
>    Do While CurTime <= EndTime
>     Application.OnTime Now(), "module"
>     For i = 1 To 9000000
>        DoEvents
>     Next i
>     Loop
> ------------------------------

  Return to Index