vba 每 15 分钟刷新整个 Excel 工作簿(所有数据连接和计算)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36867158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Refresh entire Excel workbook (all data connections and calculations) every 15 minutes?
提问by user1266515
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 all data connectionsand all calculationson all the worksheetsin my workbook every 15 minutes?
是否有时间元素可以添加到此代码中,以每 15 分钟刷新一次工作簿中所有工作表上的所有数据连接和所有计算?
The workbook has cells pulling data from SharePoint list items and contain typical formula calculations as well.
该工作簿具有从 SharePoint 列表项中提取数据的单元格,并且还包含典型的公式计算。
Sub Workbook_RefreshAll()
ActiveWorkbook.RefreshAll
End Sub
采纳答案by 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()
开始流程运行StartTimer()和结束流程运行StopTimer()
Adapted from Chip Pearson's Site
I used some Shapes to run the macros:
改编自Chip Pearson 的网站,
我使用了一些形状来运行宏:
回答by Ralph
You can use the Application.OnTimemethod to schedule a macro to be run in the future: https://msdn.microsoft.com/en-us/library/office/ff196165.aspx
您可以使用该Application.OnTime方法来安排将来运行的宏: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.OnTimeto ensure a calling "every 15 minutes".
然而,这只是一次事件。为了使其递归,您必须在该宏中(再次)包含另一个Application.OnTime以确保“每 15 分钟”调用一次。
回答by Kellsens
to refresh all calculations you can use:
刷新您可以使用的所有计算:
application.Calculate
P.S.: Sorry my english
PS:对不起我的英语


