your open event should schedule the macro once only storing the run time in a public variable. the macro should then update the run time for the next interval and reschedule itself. the beforeclose event of the workbook should then cancel the scheduled run using the final parameter of Ontime
Private Sub Workbook_Open()
RunWhen = now() + timeserial(0, 0, 30)
Application.OnTime runwhen, "Open_SFCDB"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime runwhen, "Open_SFCDB", , False
end sub
Normal module
Public RunWhen as Date
Sub Open_SFCDB()
' existing code here
RunWhen = now() + timeserial(0, 16, 0)
Application.OnTime runwhen, "Open_SFCDB"
End Sub
Bookmarks