Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Selection.InsertFormula Method

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

Namespace:  Microsoft.Office.Interop.Word
Assembly:  Microsoft.Office.Interop.Word (in Microsoft.Office.Interop.Word.dll)
void InsertFormula(
	ref Object Formula,
	ref Object NumberFormat
)

Parameters

Formula
Type: System.Object%
Optional Object. 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
Type: System.Object%
Optional Object. A format for the result of the = (Formula) field.

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

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, Microsoft Word uses the following rules to determine which SUM function to insert:

  • If the cell immediately above the insertion point contains a value, Word inserts {=SUM(ABOVE)}.

  • If the cell immediately above the insertion point doesn't contain a value but the cell immediately to the left of the insertion point does, Word inserts {=SUM(LEFT)}.

  • If neither cell immediately above the insertion point nor the cell immediately below it contains a value, Word inserts {=SUM(ABOVE)}.

  • If you don't specify Formula and all the cells above and to the left of the insertion point are empty, using the = (Formula) field causes an error.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.