For macros that modify the workbook, having Excel update or recalculate after each individual change can result in poor performance.
It is quite common to temporarily disable Excel’s screen updating and automatic calculations while performing such changes to the workbook in a macro.
PyXLL provides the context manager xl_disable for this purpose. The same can be acheived
using the Excel Object Model (see Python as a VBA Replacement), but using xl_disable can be more convenient.
The following example shows how xl_disable can be used to temporarily disable screen updating
and automatic calculations while making an update to the workbook:
@xl_macro
def macro_function():
with xl_disable():
# do some work here that updates Excel where we do not
# want Excel to automatically recalculate or update.
xl = xl_app()
xl.Range("A1").Value = 1
# After the with block, Excel reverts to its previous calculation mode.
return
Similar options are available when using the xl_macro decorator to disable updating and calculations
for the duration of the entire macro.