VBA code to complete a macro in one go
I searched around trying to find a way to just get the macro to stop working at 13:15. I found things that will close the workbook at a specific time, but nothing will leave the workbook open and just stop the macro. I believe it has to do with the function Application.OnTime "13:15:00"
, but I'm not sure how to get it to stop the macro at 13:15.
This is what keeps my excel workbook: First, when I open the workbook, this works:
Private Sub Workbook_Open()
If Time > TimeSerial(6, 45, 0) Then
Call TimeStamp
Else
Application.Wait "06:45:00"
Call TimeStamp
End Sub
Then the Macro TimeStamp will run and run every 15 minutes using these globals and encoding:
Option Explicit
Public RunWhen As Double
Public Const cRunIntervalSeconds = 900 ' 15 minutes
Public Const cRunWhat = "TimeStamp" ' the name of the procedure to run
Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
Schedule:=True
After this section, my TimeStamp macro ends with: Call StartTimer
to schedule the next execution time 15 minutes from the current time.
+3
source to share