View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Auto refresh data once a day?

Option Explicit
Dim NextTime As Date

Sub ScheduleRun()
'Schedule for tomorrow at 6:30 AM
NextTime = Date + 1 + TimeValue("06:30:00")
Application.OnTime NextTime, "RunMe"
End Sub

Sub RunMe()
MsgBox "Hello"
'Run your PivotTableRefreshAll macro from here
'Schedule for the next day (optional)...
'You cannot shut down Excel for this to work
Application.OnTime NextTime + 1, "RunMe", schedule:=True
End Sub

Sub StopMe()
'Needed if you auto scheduled for tomorrow
MsgBox "Goodbye"
'Un-schedule for tommorrow...
Application.OnTime NextTime + 1, "RunMe", schedule:=Falseue
End Sub

Sub StopMeToday()
'Needed if you want to stop before 6:30AM
MsgBox "Goodbye"
'Un-schedule for today...
Application.OnTime NextTime, "RunMe", schedule:=Falseue
End Sub


HTH,
Bernie
MS Excel MVP


"Cam" wrote in message
...
Hello,

I have several pivot table in different worksheets that I would like to
automate it to refresh all tables everyday @ 6:30AM. I created a refresh All
macro, but don't know how to tell it to execute at the given time each day.
Any help is appreciated. Thanks