# Cell.Formula 方法 (Word)Cell.Formula method (Word)

## 语法Syntax

expressionexpression. `Formula`( `_Formula_` , `_NumFormat_` )

expression：必需。expression Required. 代表单元格对象的变量。A variable that represents a 'Cell' object.

## 参数Parameters

FormulaFormula 可选Optional VariantVariant 希望 = (Formula) 域求值的数学公式。The mathematical formula you want the = (Formula) field to evaluate. 可以使用与电子表格类似的方式引用表格中的单元格。Spreadsheet-type references to table cells are valid. 例如，"=SUM(A4:C4)"指定第四行中的前三个值。For example, "=SUM(A4:C4)" specifies the first three values in the fourth row. 有关 = (Formula) 域的详细内容，请参阅域代码：= (Formula) 域。For more information about the = (Formula) field, see Field codes:= (Formula) field.
NumFormatNumFormat 可选Optional VariantVariant = (Formula) 域的结果的格式。A format for the result of the = (Formula) field. 有关可应用的格式类型的信息，请参阅"数字图片 (#)"域开关。For information about the types of formats you can apply, see Numeric Picture (#) field switch.

## 注解Remarks

• 如果紧邻插入点上面的单元格中含有数值，则 Word 插入 {=SUM(ABOVE)}。If the cell immediately above the insertion point contains a value, Word inserts {=SUM(ABOVE)}.

• 如果紧邻插入点上面的单元格中不包含数值，而紧邻插入点左面的单元格中含有数值，则 Word 插入 {=SUM(LEFT)}。If the cell immediately above the insertion point doesn't contain a value and the cell immediately to the left of it does, Word inserts {=SUM(LEFT)}.

• 如果紧邻单元格中均不包含数值，则 Word 插入 {=SUM(ABOVE)}。If neither adjoining cell 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, the result of the field is an error.

## 示例Example

``````Set myRange = ActiveDocument.Range(0, 0)
Set myTable = ActiveDocument.Tables.Add(myRange, 3, 3)
With myTable
.Cell(1,1).Range.InsertAfter "100"
.Cell(2,1).Range.InsertAfter "50"
.Cell(3,1).Formula Formula:="=Average(Above)"
End With
``````

``````Selection.Collapse Direction:=wdCollapseStart
If Selection.Information(wdWithInTable) = True Then
Selection.Cells(1).Formula Formula:="=Max(Above)"
Else
MsgBox "The insertion point is not in a table."
End If
``````