AutoSum 方法

       

插入一个 = (Formula) 域,以计算和显示表达式指定的位于表格某一单元格上方或左侧的各单元格的数值之和。有关 Word 如何确定需要相加数值的内容,请参阅 Formula 方法。

expression.AutoSum

expression   必需。一个返回 Cell 对象的表达式。

示例

本示例在新文档中创建一个 3x3 表格,并累加第一列中的数值。

Dim docNew as Document
Dim tableNew as Table

Set docNew = Documents.Add 
Set tableNew = docNew.Tables.Add(Selection.Range, 3, 3)

With tableNew
    .Cell(1,1).Range.InsertAfter "10"
    .Cell(2,1).Range.InsertAfter "15"
    .Cell(3,1).AutoSum
End With

本示例累加插入点所在的单元格上方或左侧的数值。

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