Jaafar Tribak
Well-known Member
- Joined
- Dec 5, 2002
- Messages
- 9,616
- Office Version
- 2016
- Platform
- Windows
It seems that passing a Date arg to the OnTime Method doesn't work... Any ideas ?
VBA Code:
Option Explicit
Private dNextRun As Date
Private Sub Workbook_Open()
RunPeriodicMacro Interval:=TimeValue("00:00:02") 'run every 2 secs.
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime dNextRun, "'" & Me.CodeName & ".RunPeriodicMacro " & 0 & "'", Schedule:=False
End Sub
Private Sub RunPeriodicMacro(ByVal Interval As Date)
dNextRun = Now + Interval
Debug.Print "NextRun @: ", dNextRun
Application.OnTime dNextRun, "'" & Me.CodeName & ".RunPeriodicMacro " & Interval & "'", Schedule:=True
End Sub