如何跳过或忽略查找表MS Word?

时间:2016-03-15 19:12:33

标签: vba ms-word word-vba

我有一个宏代码(由Davy C创建)来查找段落样式并为每个样式添加注释(如果找到)。我需要改进这段代码。我想只运行这个宏代码段落,并在找到时需要跳过/忽略表格。我该怎么做?

Sub CheckKeepWithNext01()
    Const message As String = "Check Keep With Next"
    Const styleMask As String = "Bold + KWN"
    Dim paragraphCount As Integer
    Dim i As Integer
    Dim currentStyle As String
    Dim doc As Document

    Set doc = ActiveDocument
    paragraphCount = doc.Paragraphs.count

    Do While i < paragraphCount
        i = i + 1

        If doc.Paragraphs(i).Range.Bold = True Then
            If doc.Paragraphs(i).KeepWithNext = False Then
                currentStyle = doc.Paragraphs(i).Range.Style

                If Left(currentStyle, Len(styleMask)) <> styleMask Then
                    doc.Paragraphs(i).Range.Select
                    Selection.Comments.Add Range:=Selection.Range
                    Selection.TypeText Text:=message
                End If
            End If
        End If
    Loop

    Set doc = Nothing
End Sub

有关更清晰的信息,请参见下面的屏幕截图:

Screenshot 01

1 个答案:

答案 0 :(得分:0)

我得到了答案!

If doc.Paragraphs(i).Range.Tables.count = 0 Then