Refresh entire Excel workbook (all data connections and calculations) every 15 minutes?

牧云@^-^@ 提交于 2019-11-29 12:34:26
Gary's Student

Enter the following in a standard module:

Public RunWhen As Double
Public Const cRunIntervalMinutes = 15
Public Const cRunWhat = "Workbook_RefreshAll"

Sub StartTimer()
    RunWhen = Now + TimeSerial(0, cRunIntervalMinutes, 0)
    Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
         schedule:=True
End Sub

Sub StopTimer()
   On Error Resume Next
   Application.OnTime earliesttime:=RunWhen, _
       procedure:=cRunWhat, schedule:=False
End Sub

Sub Workbook_RefreshAll()
    Application.CalculateFullRebuild
    ActiveWorkbook.RefreshAll
    Call StartTimer
End Sub

To begin the process run StartTimer() and to end the process run StopTimer()

Adapted from Chip Pearson's Site

I used some Shapes to run the macros:

You can use the Application.OnTime method to schedule a macro to be run in the future: https://msdn.microsoft.com/en-us/library/office/ff196165.aspx

Yet, this is a one time event only. To make it recursive, you'll have to include in that macro (yet again) another Application.OnTime to ensure a calling "every 15 minutes".

to refresh all calculations you can use:

application.Calculate

P.S.: Sorry my english

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!