Application.Wait Not Working ???

A

Alan

I have the following code for pausing before trying an Internet
connection (one of a number of them). However, it just hangs there.
I am using Windows XP and Excel 2003.

Sub WaitSeconds(seconds As Integer)
'
' This subroutine waits for a specified number of seconds.
'
Dim CurrentHour As Integer, CurrentMinute As Integer,
CurrentSecond As Integer
Dim newHour As Integer, newMinute As Integer, newSecond As Integer
Dim waitTime As Integer, CurrentTime As Integer
CurrentHour = Hour(Now())
CurrentMinute = Minute(Now())
CurrentSecond = Second(Now())
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + seconds
waitTime = TimeSerial(newHour, newMinute, newSecond)
Debug.Print "Current time = " & CurrentHour & ":" & CurrentMinute
& _
":" & CurrentSecond
Debug.Print "Waiting until " & newHour & ":" & newMinute & _
":" & newSecond
Application.Wait waitTime
End Sub

Any ideas why it would do this??

I call the subroutine above like this when it hangs:

WaitSeconds (2)

Thanks, Alan
 
M

Mike H

Alan,

Try this

Sub WaitSeconds(seconds As Integer)
' This subroutine waits for a specified number of seconds.
'
Dim CurrentHour As Integer, CurrentMinute As Integer, CurrentSecond As
Integer
Dim newHour As Integer, newMinute As Integer, newSecond As Integer
Dim waitTime As Variant, CurrentTime As Long
CurrentHour = Hour(Now())
CurrentMinute = Minute(Now())
CurrentSecond = Second(Now())
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + seconds
waitTime = TimeSerial(newHour, newMinute, newSecond)

Debug.Print "Current time = " & CurrentHour & ":" & CurrentMinute & _
":" & CurrentSecond
Debug.Print "Waiting until " & newHour & ":" & newMinute & _
":" & newSecond
Application.Wait waitTime
Debug.Print Now

End Sub

Mike
 
B

Bernie Deitrick

Use actual date time values

Sub WaitSeconds(Seconds As Integer)
' This subroutine waits for a specified number of seconds.
'
Dim CurrentTime As Date
Dim FinishTime As Date
CurrentTime = Now
FinishTime = Now + Seconds / 24 / 60 / 60

Debug.Print "Current time = " & Format(CurrentTime, "mmm dd, yyyy hh:mm:ss")
Debug.Print "Waiting until " & Format(FinishTime, "mmm dd, yyyy hh:mm:ss")
Application.Wait FinishTime
Debug.Print "I have finished waiting at " & Format(Now, "mmm dd, yyyy hh:mm:ss")

End Sub


HTH,
Bernie
MS Excel MVP
 
S

Simon Lloyd

it seems that you have the application waiting for a time that occurre
prior to executing Application.Wait so (it seems to me) that it woul
have to wait 24hrs before releasing, normally you execute the Wai
command like this
Application.Wait (Now() + TimeValue("00:00:30")

Alan;263037 said:
I have the following code for pausing before trying an Interne
connection (one of a number of them). However, it just hangs there
I am using Windows XP and Excel 2003


Sub WaitSeconds(seconds As Integer

' This subroutine waits for a specified number of seconds

Dim CurrentHour As Integer, CurrentMinute As Integer
CurrentSecond As Intege
Dim newHour As Integer, newMinute As Integer, newSecond As Intege
Dim waitTime As Integer, CurrentTime As Intege
CurrentHour = Hour(Now()
CurrentMinute = Minute(Now()
CurrentSecond = Second(Now()
newHour = Hour(Now()
newMinute = Minute(Now()
newSecond = Second(Now()) + second
waitTime = TimeSerial(newHour, newMinute, newSecond
Debug.Print "Current time = " & CurrentHour & ":" & CurrentMinut
&
":" & CurrentSecon
Debug.Print "Waiting until " & newHour & ":" & newMinute &
":" & newSecon
Application.Wait waitTim
End Su

Any ideas why it would do this?

I call the subroutine above like this when it hangs

WaitSeconds (2

Thanks, Ala

--
Simon Lloy

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com
 

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