Word VBA - 查找重复的段落但忽略某些样式

时间:2017-03-24 13:10:03

标签: vba ms-word duplicates paragraphs

以下代码适用于在Word文档中查找完全相同的段落。它忽略了比min_chars长度短的段落,但我也希望它忽略某种风格的段落。

所以有人可以帮助我添加语法或者如果左(段落样式,3)<> " XXX" '到第一个If语句?

非常感谢!

ReDim Para_text(1 To Para_count) 'i.e. to last paragraph in document

For Para_num = 1 To Para_count
    Para_text(Para_num) = ActiveDocument.Paragraphs(Para_num).range.Text
Next Para_num

For Para_A = 1 To Para_count
    For Para_B = Para_A + 1 To (Para_count - 1)
'Ignore paragraphs < min_chars characters in length (entered on user form, default 100)
    If Para_text(Para_A) Like "**" Or Para_text(Para_B) Like "**" Or Len(Para_text(Para_A)) < Form_min_chars_box Or Len(Para_text(Para_B)) < Form_min_chars_box Then 
    Else
        If Para_text(Para_A) = Para_text(Para_B) Then
        ActiveDocument.Paragraphs(Para_A).range.Select
        Page_A = Selection.Information(wdActiveEndPageNumber)
        ActiveDocument.Paragraphs(Para_B).range.Select
        Page_B = Selection.Information(wdActiveEndPageNumber)
    ' Add a comment at this found location:
        Call Repeat_Comment(Count_repeats, Para_A, Para_B, Page_A, Page_B)
    End If
End If
Next Para_B
Next Para_A


Sub Repeat_Comment(Count_repeats As Integer, Para_A As Integer, Para_B As Integer, Page_A As Integer, Page_B As Integer)
'Adds a comment whenever a duplicate paragraph is found
Count_repeats = Count_repeats + 1
Selection.Paragraphs(1).range.Characters(1).Select
    With ActiveDocument.Comments.Add(Selection.range, "This paragraph is also on page " & Page_A)
        .Initial = "Repeat "
        .Author = "Repeated"
    End With
End Sub

0 个答案:

没有答案