InsertFormula Method

See Also         Example         Applies To

Inserts an = (Formula) field that contains a formula at the selection.

Note   The formula replaces the selection, if the selection isn't collapsed.

Syntax

expression.Formula(Formula, NumberFormat)

expression   Required. An expression that returns a Selection object.

Formula   Optional Variant. The mathematical formula you want the = (Formula) field to evaluate. Spreadsheet-type references to table cells are valid. For example, "=SUM(A4:C4)" specifies the first three values in the fourth row.

NumberFormat   Optional Variant. A format for the result of the = (Formula) field.

Remarks

If you're using a spreadsheet application, such as Microsoft Excel, embedding all or part of a worksheet in a document is often easier than using the = (Formula) field in a table.

The Formula argument is optional only if the selection is in a cell and there's at least one cell that contains a value above or to the left of the cell that contains the insertion point. If the cells above the insertion point contain values, the inserted field is {=SUM(ABOVE)}; if the cells to the left of the insertion point contain values, the inserted field is {=SUM(LEFT)}. If both the cells above the insertion point and the cells to the left of it contain values, Word uses the following rules to determine which SUM function to insert: