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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Timer event 2
Scheduling Procedures With OnTime 3
making a countdown timer 1
Workbook-Close StopTimer event 2
ontime error 2
Links to Update every 10 seconds... 2
On_timer Q 3
Excel can't find macro 2

Top