I subscribe to a service that sends real-time updating stock prices directly to my spreadsheets. (Hoadley Financial Add-Ins for Excel.)
Using various posts on this site, and much trial and error, I cobbled together a little VBA code that monitors these stock prices and notifies me when my open position's profit has reached a new high and when it falls X percent below that high. I am using scheduled Application.OnTime updates to revise my potential gain when new highs are reached and to trigger an announcement when the percent drop is reached. My code is working well with one significant exception -- My macro to discontinue the Application.OnTime updates is not stopping the process. I think I have not yet formatted the command properly, but I really do not know what I am doing wrong.
I have listed my Application.OnTime macros below. (I suspect there's a better way to post my code as an attachment or insert to MrExcel, but I couldn't find any instruction for doing this. Apologies.) There are other macros referenced in the below code but I did not include them because I believe they are irrelevant to my current issue.
Once the updating process is initiated it continues indefinitely, even after I invoke the StopTimer macro.
I would really appreciate it if you would critique my code and suggest how I can revise the StopTimer macro to turn off the Application.OnTime updates. Thanks.
Here are the macros:
SubSetTime()
'set the interval for running this code from "Now"
SchedRecalc= Now + TimeValue("00:05:00")
Application.OnTimeSchedRecalc, "Recalc"
End Sub
SubRecalc()
'code to achieve task goes here
Application.Run"Macro1"
Application.Run"Macro2"
Range("F21").Value= Now
CallSetTime
End Sub
SubStopTimer()
On ErrorResume Next
Application.OnTimeSchedRecalc, "Recalc", ,schedule:=False
WithApplication.Speech
.Speak("Automatic updating is stopped.")
End With
End Sub
Using various posts on this site, and much trial and error, I cobbled together a little VBA code that monitors these stock prices and notifies me when my open position's profit has reached a new high and when it falls X percent below that high. I am using scheduled Application.OnTime updates to revise my potential gain when new highs are reached and to trigger an announcement when the percent drop is reached. My code is working well with one significant exception -- My macro to discontinue the Application.OnTime updates is not stopping the process. I think I have not yet formatted the command properly, but I really do not know what I am doing wrong.
I have listed my Application.OnTime macros below. (I suspect there's a better way to post my code as an attachment or insert to MrExcel, but I couldn't find any instruction for doing this. Apologies.) There are other macros referenced in the below code but I did not include them because I believe they are irrelevant to my current issue.
Once the updating process is initiated it continues indefinitely, even after I invoke the StopTimer macro.
I would really appreciate it if you would critique my code and suggest how I can revise the StopTimer macro to turn off the Application.OnTime updates. Thanks.
Here are the macros:
SubSetTime()
'set the interval for running this code from "Now"
SchedRecalc= Now + TimeValue("00:05:00")
Application.OnTimeSchedRecalc, "Recalc"
End Sub
SubRecalc()
'code to achieve task goes here
Application.Run"Macro1"
Application.Run"Macro2"
Range("F21").Value= Now
CallSetTime
End Sub
SubStopTimer()
On ErrorResume Next
Application.OnTimeSchedRecalc, "Recalc", ,schedule:=False
WithApplication.Speech
.Speak("Automatic updating is stopped.")
End With
End Sub
Last edited: