Preface VBA code optimization technology and strategy VBA 是否减慢了工作簿的速度?我们讨论一下Excel VBA和宏的优化技术。 Is VBA slowing down your workbooks? lets talk about optimization techniques for Excel VBA & Macros.
1 在运行宏之前关闭不需要的功能Turn off the Features you don’t want before running your Macro
这很容易理解,即使在宏运行时,Excel也会做很多工作来更新电子表格屏幕,重新计算公式,显示警报等。您可以在运行宏之前关闭这些功能,这将立即加快代码速度。下面代码您可以尝试做到这一点: This is easy pick. Even while your macros are running, Excel does a lot of work to update the spreadsheet screen, re-calculate the formulas, display alerts etc. You can turn-off these things before running your macro and this would instantly speed up your code.This is how you can do it: Application.ScreenUpdating = falseApplication.DisplayAlerts = false 最后打开警报及屏幕更新。 and use these lines at the bottom of your code to turn on the alerts & screenupdating. Application.ScreenUpdating = trueApplication.DisplayAlerts = true 但要注意:1)如果宏更改了电子表格的一部分(例如动画、图表更新),则关闭屏幕更新不是可行的方法。2) 如果计算模式正常,则将其设置为手动(application.Calculation =xlCalculationManual)3)确保在宏的末尾打开所有内容。 Things to remember:1)If your macro changes a part of the spreadsheet (for example animation, chart updation), turning off screenupdating is not the way to go.2)Set calculation mode to manual if it is ok (application.Calculation =xlCalculationManual)3)Make sure your turn-on everything at the end of your macro. (待续) 【分享成果,随喜正能量】我20多年的VBA实践经验,全部浓缩在下面的各个教程中: 【分享成果,随喜正能量】生命是如此奇妙,不是被生活打败,而是征服自己倦怠的心态。豁达,乐观,包容柔软,改良悲观,突围困顿,化解倦怠,呈现生机。 。