vba MS Excel - 如何每 5 秒自动刷新一次单元格?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40199060/
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
MS Excel - How to refresh a cell automatically every 5 seconds?
提问by Totallama
I have a cell in my Excel sheet and I need this cell to be refreshed every 5 seconds.
我的 Excel 工作表中有一个单元格,我需要每 5 秒刷新一次该单元格。
MS Excel itself enables to set refreshing but it is only every 1 minute and that is insufficiently too long..
MS Excel 本身可以设置刷新,但它只是每 1 分钟一次,而且时间不够长。
I need some code in VBA or macro set to be run every 5 seconds and do exactly what would be done if I clicked Refresh every 5 seconds as it is shown here:
我需要 VBA 中的一些代码或宏集每 5 秒运行一次,并准确执行如果我每 5 秒单击一次刷新会执行的操作,如下所示:
Somehow I didn't find any example of that I have absolutely no clue how to do that as I don't know how to work in VBA..
不知何故,我没有找到任何例子,我完全不知道如何做到这一点,因为我不知道如何在 VBA 中工作..
采纳答案by Totallama
Got it, now it works:
明白了,现在可以运行了:
Sub UpdateCell()
ActiveWorkbook.RefreshAll
Application.OnTime Now + TimeValue("00:00:5"), "List1.UpdateCell"
End Sub
回答by AlbertLau14100
You can use Application.OnTime to schedule the auto refresh. Do create the below VBA subroutine and execute. It will auto calculate cell A1 every 5 seconds.
您可以使用 Application.OnTime 来安排自动刷新。创建下面的 VBA 子程序并执行。它将每 5 秒自动计算一次单元格 A1。
Sub UpdateCell()
ActiveWorkbook.RefreshAll
Application.OnTime Now + TimeValue("00:00:5"), "UpdateCell"
End Sub
回答by Gary Carlyle Cook
The other answer describe how to refresh the whole page but the guy asking the question said he only wanted to update one specific cell.
另一个答案描述了如何刷新整个页面,但提出问题的人说他只想更新一个特定的单元格。
This is how to update (calculate) cell A1 every 5 seconds.
这是每 5 秒更新(计算)单元格 A1 的方法。
Sub Calculate_Range()
Range("G3").Calculate
Application.OnTime DateAdd("s", 5, Now), "Calculate_Range"
End Sub


