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)

Usage

Dim Formula As Object
Dim NumberFormat As Object
Dim selection1 As Selection
selection1.InsertFormula(Formula, NumberFormat)

Syntax

Sub InsertFormula( _
    <InAttribute()> Optional ByRef Formula As Object, _
    <InAttribute()> Optional ByRef NumberFormat As Object _
)
void InsertFormula(
    [In, Optional] ref object Formula, 
    [In, Optional] ref object NumberFormat
);
public: Void InsertFormula(
    &Object^ Formula, 
    &Object^ NumberFormat
);
public void InsertFormula(
    /*in*/System.Object Formula, 
    /*in*/System.Object NumberFormat
);
function InsertFormula(
     Formula : Object, 
     NumberFormat : Object
);

Parameters

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

Remarks

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.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows XP Home Edition, Windows XP Professional, Windows Server 2003, and Windows 2000

Target Platforms

See Also

Reference

Selection Interface
Microsoft.Office.Interop.Word Namespace

Other Resources

Selection Members