InsertStyleSeparator 方法

       

插入特殊隐藏段落标记,使 Microsoft Word 可以使用不同的段落样式合并段落格式,以便在目录中插入内置标题。

expression.InsertStyleSeparator

expression   必需。该表达式返回“应用于”列表中的一个对象。

示例

本示例在格式设为内置“标题 4”样式的每个段落后插入样式分隔符。

注意  段落统计位于 Do...Loop 之内,因为当 Word 插入一个样式分隔符之后,两段变成一段,所以当该程序运行时,文档的段落统计就发生改变。

Sub InlineHeading()
    Dim intCount As Integer
    Dim intParaCount As Integer

    intCount = 1

    With ThisDocument
        Do
            'Look for all paragraphs formatted with "Heading 4" style
            If .Paragraphs(Index:=intCount).Style = "Heading 4" Then
                .Paragraphs(Index:=intCount).Range.Select

                'Insert a style separator if paragraph
                'is formatted with a "Heading 4" style
                Selection.InsertStyleSeparator
            End If
            intCount = intCount + 1
            intParaCount = .Paragraphs.Count
        Loop Until intCount = intParaCount

    End With
End Sub