Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default OnTime Application Newbie Question

I have cobbled together Chip Pearson's code for running an macro queries of
Yahoo Finance for stock data (code also borrowed). Here's the basic structure
so far:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 120 ' two minutes
Public Const cRunWhat = "GetData" ' the name of the procedure to run

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat,
Schedule:=True
End Sub

Sub GetData()
<my code
StartTimer
End Sub

There is also another generic piece of code courtesy of Mr. Pearson:

Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat,
Schedule:=False
End Sub

...but it is not currently being called.

I want to 1) GetData (see above) between 9:00 and 15:30 daily only (this
spreadsheet will reside on a dedicated computer, hopefully always on), and 2)
perform other macros at, say, 8:30 and 16:00 daily. I am uncertain how these
last two items get coded. Any help appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default OnTime Application Newbie Question

Public RunWhen As Double
Public Const cRunIntervalSeconds = 120 ' two minutes
Public cRunWhat As String ' the name of the procedure to run

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
If RunWhen - Int(RunWhen) = TimeSerial(8, 30, 0) And _
RunWhen - Int(RunWhen) <= TimeSerial(16, 0, 0) Then
cRunWhat = "GetData"
Else
cRunWhat = "StartTimer"
End If
Application.OnTime EarliestTime:=RunWhen, _
Procedu=cRunWhat, _
Schedule:=True
End Sub

Sub GetData()
MsgBox "hello" '<my code
StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=RunWhen, _
Procedu=cRunWhat, _
Schedule:=False
End Sub



--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"John V" wrote in message
...
I have cobbled together Chip Pearson's code for running an macro queries of
Yahoo Finance for stock data (code also borrowed). Here's the basic
structure
so far:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 120 ' two minutes
Public Const cRunWhat = "GetData" ' the name of the procedure to run

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat,
Schedule:=True
End Sub

Sub GetData()
<my code
StartTimer
End Sub

There is also another generic piece of code courtesy of Mr. Pearson:

Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat,
Schedule:=False
End Sub

..but it is not currently being called.

I want to 1) GetData (see above) between 9:00 and 15:30 daily only (this
spreadsheet will reside on a dedicated computer, hopefully always on), and
2)
perform other macros at, say, 8:30 and 16:00 daily. I am uncertain how
these
last two items get coded. Any help appreciated.



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
Help with Application.OnTime [email protected] Excel Programming 1 April 3rd 06 06:02 PM
Application OnTime...need some help to schedule. wayliff[_14_] Excel Programming 1 January 19th 06 07:47 PM
application.ontime rick Excel Programming 2 July 25th 05 06:09 PM
OnTime Unusual Application Peter[_52_] Excel Programming 4 January 19th 05 05:59 AM
Application.OnTIme Mike Excel Programming 8 September 15th 04 03:27 PM


All times are GMT +1. The time now is 09:18 AM.

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"