Thread
:
Wierd one concerning Before_Close and OnTime
View Single Post
#
7
Posted to microsoft.public.excel.misc
Ardus Petus
Posts: n/a
Wierd one concerning Before_Close and OnTime
Yes it will!
--
AP
"Antonio" a écrit dans le message de
news:
...
Hi Ardus,
Yes, I understand your code. refreshdata is run every 18'' past the hour.
That is equivalent to what I was doing.
However, it does not answer the original question. If you call the
cancelTimer from the BeforeClose method it won't execute
"Ardus Petus" wrote:
Here's an example (whole module):
'-------------------------------------------------
Option Explicit
Dim dNext As Date
Sub Auto_Open()
dNext = TimeSerial(Hour(Now) + IIf(Minute(Now) < 18, 0, 1), 18, 0)
Application.OnTime dNext, "refreshdata"
End Sub
Sub refreshdata()
MsgBox Now
dNext = TimeSerial(Hour(dNext) + 1, 18, 0)
Application.OnTime dNext, "refreshdata"
End Sub
Sub cancelTimer()
Application.OnTime dNext, "refreshdata", , False
End Sub
'--------------------------------------------------------
HTH
--
AP
"Antonio" a écrit dans le message de
news:
...
Hi Ardus,
Excuse the simple question, how do I maintain a global variable?
I have used a Public one to no avail.
Thanks,
Antonio
"Ardus Petus" wrote:
You could maintain a global variable that holds the timer value.
Please post your code.
HTH
--
AP
"Antonio" a écrit dans le message
de
news:
...
The following kills the OnTime max_min when the workbook is closed
normally
Public Sub Workbook_BeforeClose(cancel As Boolean)
kill_max_min
End Sub
Public Sub kill_max_min()
Application.OnTime TimeValue(Hour(Now) & ":" & Minute(Now)) +
TimeValue("00:01"), "max_min", , False
End Sub
However, when the workbook is closed from a different module with
the
Workbook. Close method, the BeforeClose above seems to run well and
runs
the
kill_max_min but the OnTime is not killed, it comes back up as
scheduled.
Why is that?
Thanks,
Antonio
Reply With Quote