Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Application.wait... won't!

Good afternoon,

Can anyone explain why the following code doesn't take 30 seconds to run...
or when called from within another macro, doesn't delay macro execution by 30
seconds?

Thanks in advance

Sub HoldOnABit()

Dim NewHour As Integer
Dim NewMinute As Long
Dim NewSecond As Long
Dim WaitTime As Long

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)

Application.Wait WaitTime

End Sub


Pete


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Application.wait... won't!

Hi Peter

I now use this method:

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

then anywhere a delay is required, put in this:

Sleep 1000 '1000 milliseconds = 1 second

For 30 seconds you would have

Sleep 30000

Hop this helps

Andrew Bourke

Peter Rooney wrote:
Good afternoon,

Can anyone explain why the following code doesn't take 30 seconds to run...
or when called from within another macro, doesn't delay macro execution by 30
seconds?

Thanks in advance

Sub HoldOnABit()

Dim NewHour As Integer
Dim NewMinute As Long
Dim NewSecond As Long
Dim WaitTime As Long

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)

Application.Wait WaitTime

End Sub


Pete


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Application.wait... won't!

Andrew,

This is neat - thanks a lot!

Regards

Pete



"Andrew B" wrote:

Hi Peter

I now use this method:

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

then anywhere a delay is required, put in this:

Sleep 1000 '1000 milliseconds = 1 second

For 30 seconds you would have

Sleep 30000

Hop this helps

Andrew Bourke

Peter Rooney wrote:
Good afternoon,

Can anyone explain why the following code doesn't take 30 seconds to run...
or when called from within another macro, doesn't delay macro execution by 30
seconds?

Thanks in advance

Sub HoldOnABit()

Dim NewHour As Integer
Dim NewMinute As Long
Dim NewSecond As Long
Dim WaitTime As Long

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)

Application.Wait WaitTime

End Sub


Pete



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Application.wait... won't!

Where are you putting the delare bub statement? I try it in the declarations
section of "ThisWorkbook", but when I go to run a sub that has the sleep in
it I get a error "sub or function not defined"

"Andrew B" wrote:

Hi Peter

I now use this method:

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

then anywhere a delay is required, put in this:

Sleep 1000 '1000 milliseconds = 1 second

For 30 seconds you would have

Sleep 30000

Hop this helps

Andrew Bourke

Peter Rooney wrote:
Good afternoon,

Can anyone explain why the following code doesn't take 30 seconds to run...
or when called from within another macro, doesn't delay macro execution by 30
seconds?

Thanks in advance

Sub HoldOnABit()

Dim NewHour As Integer
Dim NewMinute As Long
Dim NewSecond As Long
Dim WaitTime As Long

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)

Application.Wait WaitTime

End Sub


Pete



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Application.wait... won't!

Try:

Dim NewHour As Integer
Dim NewMinute As Integer
Dim NewSecond As Integer

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30

Application.Wait TimeSerial(NewHour, NewMinute, NewSecond)


"Peter Rooney" wrote:

Good afternoon,

Can anyone explain why the following code doesn't take 30 seconds to run...
or when called from within another macro, doesn't delay macro execution by 30
seconds?

Thanks in advance

Sub HoldOnABit()

Dim NewHour As Integer
Dim NewMinute As Long
Dim NewSecond As Long
Dim WaitTime As Long

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)

Application.Wait WaitTime

End Sub


Pete




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Application.wait... won't!

Hmm...even better is simply:

Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 30)


"Charlie" wrote:

Try:

Dim NewHour As Integer
Dim NewMinute As Integer
Dim NewSecond As Integer

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30

Application.Wait TimeSerial(NewHour, NewMinute, NewSecond)


"Peter Rooney" wrote:

Good afternoon,

Can anyone explain why the following code doesn't take 30 seconds to run...
or when called from within another macro, doesn't delay macro execution by 30
seconds?

Thanks in advance

Sub HoldOnABit()

Dim NewHour As Integer
Dim NewMinute As Long
Dim NewSecond As Long
Dim WaitTime As Long

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)

Application.Wait WaitTime

End Sub


Pete


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Application.wait... won't!

Charlie,

Thanks a lot for this - it works a treat!

Regards

Pete



"Charlie" wrote:

Hmm...even better is simply:

Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 30)


"Charlie" wrote:

Try:

Dim NewHour As Integer
Dim NewMinute As Integer
Dim NewSecond As Integer

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30

Application.Wait TimeSerial(NewHour, NewMinute, NewSecond)


"Peter Rooney" wrote:

Good afternoon,

Can anyone explain why the following code doesn't take 30 seconds to run...
or when called from within another macro, doesn't delay macro execution by 30
seconds?

Thanks in advance

Sub HoldOnABit()

Dim NewHour As Integer
Dim NewMinute As Long
Dim NewSecond As Long
Dim WaitTime As Long

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)

Application.Wait WaitTime

End Sub


Pete


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Application.wait... won't!

I would suspect that the help example you copied is flawed. to
demonstrate:

Sub BB()
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
waittime = TimeSerial(newHour, newMinute, newSecond)
waittime1 = Now + TimeValue("0:00:10")
Debug.Print waittime, waittime1
Debug.Print CSng(waittime), CSng(waittime1)
End Sub

Produces:
7:51:28 AM 09/08/2005 7:51:28 AM
0.3274074 38603.33

Use this instead:

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
waittime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait Date + waittime

or just

waittime1 = Now + TimeValue("0:00:10")
Application.Wait WaitTime1

--
Regards,
Tom Ogilvy


"Peter Rooney" wrote in message
...
Good afternoon,

Can anyone explain why the following code doesn't take 30 seconds to

run...
or when called from within another macro, doesn't delay macro execution by

30
seconds?

Thanks in advance

Sub HoldOnABit()

Dim NewHour As Integer
Dim NewMinute As Long
Dim NewSecond As Long
Dim WaitTime As Long

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)

Application.Wait WaitTime

End Sub


Pete




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Application.wait... won't!

Tom,

This is great, thanks!
I got my original code from Excel help!!!

One thing, when I declare a the WaitTime1 variable, the code only works
correctly if I give specify type Variant or Double. I know I can't use
integer or long, as they only wotk with integers, but do you have any idea
what's wrong with "single" in this instance?

Thanks

Pete

"Tom Ogilvy" wrote:

I would suspect that the help example you copied is flawed. to
demonstrate:

Sub BB()
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
waittime = TimeSerial(newHour, newMinute, newSecond)
waittime1 = Now + TimeValue("0:00:10")
Debug.Print waittime, waittime1
Debug.Print CSng(waittime), CSng(waittime1)
End Sub

Produces:
7:51:28 AM 09/08/2005 7:51:28 AM
0.3274074 38603.33

Use this instead:

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
waittime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait Date + waittime

or just

waittime1 = Now + TimeValue("0:00:10")
Application.Wait WaitTime1

--
Regards,
Tom Ogilvy


"Peter Rooney" wrote in message
...
Good afternoon,

Can anyone explain why the following code doesn't take 30 seconds to

run...
or when called from within another macro, doesn't delay macro execution by

30
seconds?

Thanks in advance

Sub HoldOnABit()

Dim NewHour As Integer
Dim NewMinute As Long
Dim NewSecond As Long
Dim WaitTime As Long

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)

Application.Wait WaitTime

End Sub


Pete





  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Application.wait... won't!

Sub BB()
Dim WaitTime1 As Single

' WaitTime1 = TimeSerial(0, 0, 10)
WaitTime1 = TimeValue("0:0:10")
Debug.Print Now, Now + WaitTime1
Application.Wait Now + WaitTime1
Debug.Print Now
End Sub

worked for me. Both using TimeSerial and TimeValue

--
Regards,
Tom Ogilvy

"Peter Rooney" wrote in message
...
Tom,

This is great, thanks!
I got my original code from Excel help!!!

One thing, when I declare a the WaitTime1 variable, the code only works
correctly if I give specify type Variant or Double. I know I can't use
integer or long, as they only wotk with integers, but do you have any idea
what's wrong with "single" in this instance?

Thanks

Pete

"Tom Ogilvy" wrote:

I would suspect that the help example you copied is flawed. to
demonstrate:

Sub BB()
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
waittime = TimeSerial(newHour, newMinute, newSecond)
waittime1 = Now + TimeValue("0:00:10")
Debug.Print waittime, waittime1
Debug.Print CSng(waittime), CSng(waittime1)
End Sub

Produces:
7:51:28 AM 09/08/2005 7:51:28 AM
0.3274074 38603.33

Use this instead:

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
waittime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait Date + waittime

or just

waittime1 = Now + TimeValue("0:00:10")
Application.Wait WaitTime1

--
Regards,
Tom Ogilvy


"Peter Rooney" wrote in message
...
Good afternoon,

Can anyone explain why the following code doesn't take 30 seconds to

run...
or when called from within another macro, doesn't delay macro

execution by
30
seconds?

Thanks in advance

Sub HoldOnABit()

Dim NewHour As Integer
Dim NewMinute As Long
Dim NewSecond As Long
Dim WaitTime As Long

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)

Application.Wait WaitTime

End Sub


Pete









  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Application.wait... won't!

Tom,

Strange - only Double works for me - if I specify single, no discernible
delay takes place. Anyway, as long as one way works (but if you're anything
like me, you don't like loose ends either!)

Cheers

Pete



"Tom Ogilvy" wrote:

Sub BB()
Dim WaitTime1 As Single

' WaitTime1 = TimeSerial(0, 0, 10)
WaitTime1 = TimeValue("0:0:10")
Debug.Print Now, Now + WaitTime1
Application.Wait Now + WaitTime1
Debug.Print Now
End Sub

worked for me. Both using TimeSerial and TimeValue

--
Regards,
Tom Ogilvy

"Peter Rooney" wrote in message
...
Tom,

This is great, thanks!
I got my original code from Excel help!!!

One thing, when I declare a the WaitTime1 variable, the code only works
correctly if I give specify type Variant or Double. I know I can't use
integer or long, as they only wotk with integers, but do you have any idea
what's wrong with "single" in this instance?

Thanks

Pete

"Tom Ogilvy" wrote:

I would suspect that the help example you copied is flawed. to
demonstrate:

Sub BB()
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
waittime = TimeSerial(newHour, newMinute, newSecond)
waittime1 = Now + TimeValue("0:00:10")
Debug.Print waittime, waittime1
Debug.Print CSng(waittime), CSng(waittime1)
End Sub

Produces:
7:51:28 AM 09/08/2005 7:51:28 AM
0.3274074 38603.33

Use this instead:

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
waittime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait Date + waittime

or just

waittime1 = Now + TimeValue("0:00:10")
Application.Wait WaitTime1

--
Regards,
Tom Ogilvy


"Peter Rooney" wrote in message
...
Good afternoon,

Can anyone explain why the following code doesn't take 30 seconds to
run...
or when called from within another macro, doesn't delay macro

execution by
30
seconds?

Thanks in advance

Sub HoldOnABit()

Dim NewHour As Integer
Dim NewMinute As Long
Dim NewSecond As Long
Dim WaitTime As Long

NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 30
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)

Application.Wait WaitTime

End Sub


Pete








  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Application.wait... won't!

Hi Peter,

"Peter Rooney"

wrote in message
...

Looks like it depends on whether "Now" is included.
So...
'86400 seconds in a day
'30/86400 = 0.0003472
'10/86400 = 0.0001157

Dim WaitTime As Double
WaitTime = Now + 0.0001157
Application.Wait WaitTime

or

Dim WaitTime as Single
WaitTime = 0.00011157
Application.Wait Now + WaitTime

Regards,
Jim Cone
San Francisco, USA
'-----------------------------


Tom,
Strange - only Double works for me - if I specify single, no discernible
delay takes place. Anyway, as long as one way works (but if you're anything
like me, you don't like loose ends either!)
Cheers
Pete

"Tom Ogilvy" wrote:
Sub BB()
Dim WaitTime1 As Single

' WaitTime1 = TimeSerial(0, 0, 10)
WaitTime1 = TimeValue("0:0:10")
Debug.Print Now, Now + WaitTime1
Application.Wait Now + WaitTime1
Debug.Print Now
End Sub
worked for me. Both using TimeSerial and TimeValue
--

Regards,
Tom Ogilvy

"Peter Rooney" wrote in message
...
Tom,


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sendkeys(keys,wait) how do I use wait MM Excel Discussion (Misc queries) 1 February 11th 09 03:47 PM
Wait less than a second Claus[_3_] Excel Programming 3 September 7th 05 01:25 PM
.wait for 1/2 a second Brad Excel Programming 18 June 9th 05 03:44 PM
Application.wait & Blinking Connector Tom Rudski[_2_] Excel Programming 1 March 6th 04 05:36 PM
wait Eddie[_4_] Excel Programming 3 November 15th 03 03:37 PM


All times are GMT +1. The time now is 07:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"