为什么 ActiveSheet.Calculate 在 VBA 中不起作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26421741/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 04:53:09  来源:igfitidea点击:

Why does ActiveSheet.Calculate not work in VBA?

excelvbaexcel-vba

提问by Bobsworth

Some Background:I have a table of counts which is graphed. When slicers are changed I need to click Calculate to update the counts and graph. (Calculation is set to manual due to workbook size). Believe it or not, using the calculate button is beyond some users.. I would like to have it as a form button easily visible next to the graph. I used the Macro recorder to find the statement for Calculate Sheet. It gave me ActiveSheet.Calculate.

一些背景:我有一个图表计数表。当切片器更改时,我需要单击计算来更新计数和图形。(由于工作簿大小,计算设置为手动)。信不信由你,使用计算按钮超出了某些用户的范围。我希望将它作为一个易于在图表旁边可见的表单按钮。我使用宏记录器来查找计算表的语句。它给了我 ActiveSheet.Calculate。

Problem:When I run ActiveSheet.Calculate from my macro button the graphs on the sheet do not update. Excel's calculate button, however, works. Surely they are functionally identical? Why does my button not update but Excel's calculate does?

问题:当我从我的宏按钮运行 ActiveSheet.Calculate 时,工作表上的图形不会更新。但是,Excel 的计算按钮有效。它们在功能上肯定相同吗?为什么我的按钮不更新但 Excel 的计算会更新?

When I change the button to use Application.Calcluate, the graphs update.

当我更改按钮以使用 Application.Calcluate 时,图形会更新。

回答by GlennFromIowa

Well, on my version of Excel (2010), there are two Calculate buttons: Calculate Now F9and Calculate Sheet Shift-F9. Calculate Now re-calculates the whole Workbook and should be functionally identical to Application.Calculate, whereas Calculate Sheet only recalculates the individual worksheet and should be functionally identical to ActiveSheet.Calculate.

好吧,在我的 Excel (2010) 版本上,有两个计算按钮:立即F9计算和计算表Shift-F9。立即计算重新计算整个工作簿,并且在功能上应该与 相同Application.Calculate,而计算工作表仅重新计算单个工作表并且在功能上应该与 相同ActiveSheet.Calculate

I would suggest using the Workbook.RefreshAllmethod or the WorkbookConnection.Refreshmethod before the ActiveSheet.Calculateto see if that has less overhead than the Application.Calculatemethod.

我建议使用该Workbook.RefreshAll方法或WorkbookConnection.Refresh之前的方法ActiveSheet.Calculate来查看是否比该Application.Calculate方法具有更少的开销。

Oh, and I can definitely believe using the calculate button is beyond some users.

哦,我绝对相信使用计算按钮超出了某些用户的范围。