TabStops 集合对象

         
多种对象
TabStops (TabStop)

该对象为 TabStop 对象组成的集合,这些元素对象代表一个或多个段落中默认或自定义制表位。

使用 TabStops 集合

可用 TabStops 属性返回 TabStops 集合。下例清除活动文档第一段中所有自定义制表位。

ActiveDocument.Paragraphs(1).TabStops.ClearAll

下例在所选段落中 2.5 英寸处添加一个制表位,并显示 TabStops 集合中每一项目的位置。

Selection.Paragraphs.TabStops.Add Position:=InchesToPoints(2.5)
For Each aTab In Selection.Paragraphs.TabStops
    MsgBox "Position = " _
        & PointsToInches(aTab.Position) & " inches"
Next aTab

可用 Add 方法添加一个制表位。下例在所选段落中增加 2 个制表位。第一个制表位为右对齐,在 1 英寸(72 磅)处有一加点的制表符前导符。第二个制表位居中,位于 2 英寸处。

With Selection.Paragraphs.TabStops
    .Add Position:=InchesToPoints(1), _
        Leader:=wdTabLeaderDots, Alignment:=wdAlignTabLeft
    .Add Position:=InchesToPoints(2), Alignment:=wdAlignTabCenter
End With

还可用 TabStops 属性在一指定位置添加制表位。下例在所选段落中增加一个右对齐制表位,位于 2 英寸处。

Selection.Paragraphs.TabStops(InchesToPoints(2)) _
    .Alignment = wdAlignTabRight

可用 TabStops(index) 返回一个 TabStop 对象,其中 index 为制表位位置(以磅为单位)或索引号。制表位沿标尺自左至右编号。下例删除活动文档第一段中的第一个自定义制表位。

ActiveDocument.Paragraphs(1).TabStops(1).Clear

下例在所选段落中增加一个右对齐制表位,位于 2 英寸处。

Selection.Paragraphs.TabStops(InchesToPoints(2)) _
    .Alignment = wdAlignTabRight

说明

使用 Paragraphs 集合(或包含多个段落的一个范围)时,如果集合中各段制表位位置不一致,就必须在各段中分别修改。下例删除活动文档中位于各段 1 英寸处的制表位。

For Each para In ActiveDocument.Content.Paragraphs
    para.TabStops(InchesToPoints(1)).Clear
Next para