OnTime VB

A

AKorsakova

I want to refresh my data every day at 12am. Does something like this
make sence?

Public RunWhen As Double

Sub StartTimer()

RunWhen = Time() = #12:00:00 AM# + TimeSerial(24, 0, 0)
Application.OnTime earliesttime:=RunWhen, procedure:="The_Sub", _
schedule:=True
End Sub

Sub The_Sub()


ActiveWorkbook.RefreshAll
StartTimer

End Sub
 
A

Ardus Petus

Sub StartTimer()
Dim RunWhen As Double
RunWhen = Time() = #12:00:00 AM# + TimeSerial(24, 0, 0)
Application.OnTime earliesttime:=RunWhen, procedure:="The_Sub", _
schedule:=True
End Sub

HTH
 
A

AKorsakova

now with something like RunWhen = date + TimeSerial(23, 59, 59)
would that automatically refresh every day- or would it just do that
one day?
 
D

Dave Peterson

It would only do it once.

But you could have your code set up the next time right after that time
finishes.

Chip shows you how at that link.
 
Top