PyXLL The Python Excel Add-In
  • Product
    • Features
    • Get Started
    • Request Demo
    • Download
  • Pricing
  • Resources
    • Documentation
    • Blog
    • Videos
    • FAQ
    • Learn Python
    • Customer Portal
    • About Us
  • Support
    • Documentation
    • Videos
    • FAQ
    • Contact Us
  • Contact Us
Table of Contents
  • PyXLL Documentation
  • Introduction to PyXLL
  • User Guide
    • Installing PyXLL
    • Configuring PyXLL
    • Worksheet Functions
    • Macro Functions
      • Introduction
      • Calling Macros From Excel
      • Accessing Worksheet Data
      • Passing Python Objects
      • Pausing Automatic Recalculation
      • Keyboard Shortcuts
    • Real Time Data
    • Cell Formatting
    • Charts and Plotting
    • Custom Task Panes
    • ActiveX Controls
    • Using Pandas in Excel
    • Customizing the Ribbon
    • Context Menu Functions
    • Working with Tables
    • Python as a VBA Replacement
    • Menu Functions
    • Reloading and Rebinding
    • Error Handling
    • Deploying your add-in
    • Workbook Metadata
  • Video Guides and Tutorials
  • API Reference
  • What’s new in PyXLL 5
  • Changelog
Close

Pausing Automatic Recalculation¶

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.

« Passing Python Objects
Keyboard Shortcuts »
  • Home
  • Product
  • Features
  • Documentation
  • Download
  • Pricing
  • Support
  • Documentation
  • Videos
  • FAQ
  • Learn Python
  • Contact Us
  • About
  • About Us
  • Legal
  • Blog
© Copyright PyXLL Ltd