Export (0) Print
Expand All
Expand Minimize

How to: Run Excel Calculations Programmatically


Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

The Calculate method runs all calculations in the specified object. Use the method of the object that limits the calculation range to the smallest number of cells that you want to recalculate. The recalculation engine in Microsoft Office Excel 2003 is very fast, but if you can limit the number of cells involved, you can optimize the operation.

Running Calculations for a Range

To run calculations in a NamedRange control

  1. Create the named range.

    Microsoft.Office.Tools.Excel.NamedRange NamedRange1 =
        this.Controls.AddNamedRange(this.get_Range("A1", missing), "NamedRange1");
  2. Call the Calculate method of the specified range.


Running Calculations for the Entire Application

To run calculations in all open workbooks

Compiling the Code

  • This code must be placed in a sheet class, not in the ThisWorkbook class.

See Also

Community Additions

© 2014 Microsoft