I have a continual looping macro (Transfer)- refer below- which I kick off with a button, running all the time. via the Application.OnTime, I trigger the next macro (TransferTallys) to run once. The problem is that it doesn't run once. It just loops and goes on and on even after the set time in the Application.OnTime argument is no longer valid. I have added the variable (Register1) that I set to 2 for 5 seconds to try to ensure that it won't run again, but to no avail. Can someone please tell me what I'm doing wrong?
Dim Register1
Sub Transfer()
--bulky code--
Application.OnTime EarliestTime:=TimeValue("X:XX:XX"), Procedure:="TransferTallys"
Application.OnTime EarliestTime:=Now() + TimeValue("00:00:5"), Procedure:="Transfer"
End Sub
Dim Register1
Sub TransferTallys()
'
' Macro1 Macro
' Macro recorded 8/6/2008 by tchilders
'
If Register1 = 1 Then
--more bulky code to tally and transfer data at end of day--
End If
Register1 = 2
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 5
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
Register1 = 1
Run "Transfer"
End Sub
Dim Register1
Sub Transfer()
--bulky code--
Application.OnTime EarliestTime:=TimeValue("X:XX:XX"), Procedure:="TransferTallys"
Application.OnTime EarliestTime:=Now() + TimeValue("00:00:5"), Procedure:="Transfer"
End Sub
Dim Register1
Sub TransferTallys()
'
' Macro1 Macro
' Macro recorded 8/6/2008 by tchilders
'
If Register1 = 1 Then
--more bulky code to tally and transfer data at end of day--
End If
Register1 = 2
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 5
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
Register1 = 1
Run "Transfer"
End Sub