- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Excel 书中有一些用户定义的函数。我使用了它们一段时间,但过了一会儿,我从单元格中删除了对这些函数的调用,因为我找到了完成相同任务的更好方法(我没有在 VBA 编辑器中删除函数定义本身)。因此,这些函数不再在书中或任何 VBA 代码中被调用,我使用搜索进行了检查以确保 100% 确定。
现在我正在对我的代码进行一些审查,我注意到一些奇怪的事情:在同一工作簿中的 Sub 过程中(与这些函数无关)我调用 Application.CalculateFullRebuild
。当发生这种情况时,那些 UDF 被调用,我可以通过在 UDF 内设置断点来看到它。
我想知道为什么会发生这种情况以及可以采取哪些措施来避免这种情况,因为它不必要地减慢了 Sub 的速度。
谢谢!
最佳答案
Application.CalculateFullRebuild
MSDN reference有这样说:
The
CalculateFullRebuild
method is similar to re-entering all formulas. ... [When run] a full calculation of the data in all open workbooks is performed and the dependencies are rebuilt.
Causes Excel to rebuild the dependency tree and the calculation chain
这意味着模块代码或工作表代码中的任何 UDF 都将被重新计算,因为 Excel 正在重建和测试计算链中函数的依赖性和使用。
如果您正在寻找一种通过 Sub
简单地手动计算工作表中现有公式的方法,您可以使用 'Application.Calculate' (MSDN) :
Application.Calculate 'for all open Sheets
Sheets("Name of Sheet").Calculate 'Specific Sheet
Sheets("Name of Sheet").Range("Name of Range").Calculate 'Specific Range
关于vba - 执行CalculateFullRebuild时调用未使用的UDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27923570/
我是一名优秀的程序员,十分优秀!