View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Vergel Adriano Vergel Adriano is offline
external usenet poster
 
Posts: 857
Default Loop for X seconds then exit

This is not a loop, but I assume you're just wanting to have some kind of
delay before executing the next line of code after the loop. If so, then you
might find this useful:

Sub Test()
Dim waitTime As Date
MsgBox "Hello, World"
waitTime = TimeSerial(Hour(Now), Minute(Now), Second(Now) + 1)
Application.Wait waitTime
MsgBox "One Second has elapsed"
End Sub



--
Hope that helps.

Vergel Adriano


"XP" wrote:

I just want to set up a Do-Loop that exits after a certain number of seconds
have elapsed. The following code does not work, but I think you will get the
idea. This does not need to be that precise, just approximate.

Could someone please correct my code to work or post some other example code
that does run? Something like:

Dim dTimeBeg as Date
Dim dTimeEnd as Date
Dim lElapsed as Long
lElapsedSeconds = 49 <<<<<<<<<this would be seconds I specify
dTimeBeg = Now()
Do
dTimeEnd = Now()
If dTimeEnd = dTimeBeg + lElapsedSeconds then Exit Do
Loop

Thanks much in advance.