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

前端 未结 3 1750
感情败类
感情败类 2020-12-20 07:12

I have the following macro to refresh my workbook. This is the same as clicking on the refresh all button.

Is there a time element I can add to this code to refresh

3条回答
  •  暖寄归人
    2020-12-20 07:15

    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:

提交回复
热议问题