Halting Execution -- A Newbie Question (possible repeat, sorry)

J

John V

Here is the code from my worksheet that continually queries the web for stock
quotes:

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, Procedure:=cRunWhat,
Schedule:=True
End Sub



Sub GetData()
<functioning web query stuff here>
StartTimer

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

Questions:
1. I have occasion to want to halt execution to update portions of the
workbook. I envision some sort of Pause and Resume code to do this. Ideas?
2. How do I modify this code to run only during business hours?

Many thanks.
 
J

Jim Thomlinson

You can not really just halt the code. What you can do however is have the
code check a global variable at run time to determine what it should do. If
the value of the global is true then run the GetData. If it is false then
just exit. This way all you need to do is to manipulate that variable to
change the way the code operates...

In short the code always runs, but it does not always do much depending on
the varaible...
 

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

Similar Threads

Stopping Code Execution -- Newbie 1
making a countdown timer 1
Stopping a timer 10
OnTime Application Newbie Question 1
Links to Update every 10 seconds... 2
Visible countdown timer 5
AutoSave 2
On_timer Q 3

Top