Note: The other languages of the website are Google-translated. Back to English
Accedi  \/ 
x
or
x
Registrati  \/ 
x

or

Come trovare ed evidenziare i paragrafi duplicati nel documento di Word?

Supponendo che tu abbia un grande documento di Word che può avere centinaia di pagine, ora, vuoi controllare se ci sono paragrafi duplicati e quindi evidenziare per renderli eccezionali, in modo da poter gestire le frasi duplicate. Come puoi trovare ed evidenziare i paragrafi duplicati in modo rapido e semplice nel documento di Word?

Trova ed evidenzia i paragrafi duplicati nel documento Word con codice VBA


Trova ed evidenzia i paragrafi duplicati nel documento Word con codice VBA

Per trovare ed evidenziare i paragrafi duplicati in un documento di Word, il seguente codice VBA può farti un favore, per favore fai come segue:

1. Tieni premuto il ALT + F11 chiavi per aprire il Microsoft Visual Basic, Applications Edition finestra.

2. Quindi fare clic su inserire > Modulo, copia e incolla sotto il codice nel modulo vuoto aperto:

Codice VBA: trova ed evidenzia i paragrafi duplicati nel documento di Word:

Sub highlightdup()
    Dim I, J As Long
    Dim xRngFind, xRng As Range
    Dim xStrFind, xStr As String
    Options.DefaultHighlightColorIndex = wdYellow
    Application.ScreenUpdating = False
    With ActiveDocument
        For I = 1 To .Paragraphs.Count - 1
            Set xRngFind = .Paragraphs(I).Range
            If xRngFind.HighlightColorIndex <> wdYellow Then
                For J = I + 1 To .Paragraphs.Count
                    Set xRng = .Paragraphs(J).Range
                    If xRngFind.Text = xRng.Text Then
                        xRngFind.HighlightColorIndex = wdBrightGreen
                        xRng.HighlightColorIndex = wdYellow
                    End If
                Next
            End If
        Next
    End With
End Sub

3. E poi premere F5 tasto per eseguire questo codice, tutte le frasi duplicate vengono evidenziate contemporaneamente, i primi paragrafi duplicati visualizzati sono evidenziati con il colore verde e gli altri duplicati sono evidenziati con il colore giallo, vedi screenshot:

doc evidenzia frasi dup 1


Strumenti di produttività Word consigliati

 

Kutools per Word: oltre 100 funzionalità avanzate per Word, risparmia il 50% del tempo

  • Le operazioni complicate e ripetute possono essere eseguite una sola volta in pochi secondi.
  • Inserisci più immagini tra le cartelle nel documento di Word contemporaneamente.
  • Unisci e combina più file di Word tra cartelle in uno con l'ordine desiderato.
  • Suddividi il documento corrente in documenti separati in base a titolo, interruzione di sezione o altri criteri.
  • Converti file tra Doc e Docx, Docx e PDF, raccolta di strumenti per conversioni e selezioni comuni e così via ...
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Vicky · 21 days ago
    Hi, mình chạy đoạn code trên nhưng không thấy ra kết quả giống bài viết, mình dùng word 2019, Ad support giúp mình nhé 
  • To post as a guest, your comment is unpublished.
    Harsh · 7 months ago
    Hi, can anyone please suggest me to prepare a macro in ms word for finding error in paragraph.

    Like:-  
    "and or" 
    "that that" 
    "of the of the" 
    "Sentence end without dot (.)" 
    "New Sentence start with initial caps without ending the sending".
  • To post as a guest, your comment is unpublished.
    Deitsa · 8 months ago
    Thanks so much.
    A very valuable article, helped me with my duplicate copies and paste paragraphs!
    You are awesome.
  • To post as a guest, your comment is unpublished.
    Tom · 1 years ago
    Tried this for my book in MS Word. First, it would not work because I had bullet points. I removed them and then it only found 2 instances "blank page" and "table of contents". I purposely have several sentences repeated, and this macro did not find them. Thank you for trying, but I would say this doesn't work.

  • To post as a guest, your comment is unpublished.
    Peter · 1 years ago
    I had a very long document to process, the code above would take at least 100 days to finish and blocked everything while working at it. The main culprit is the "Set xRng = .Paragraphs(J).Range" which is very slow. I did an alternative version which ran in just 4 hours and presents a continuous report on the processing status and time to end. (To see the report in real time you have to open the "immediate window" by pressing Ctrl+G in the Microsoft Visual Basic for Applications window.) The code works well, except that it predicts a longer time to end than is actually the case (depends on the document). The code is as follows:

    Sub highlightdup()
    Dim StartTime, SecondsElapsed As Date
    Dim secondsPerComparison As Double
    Dim I, J, PC, totalComparisons, comparisonsDone, C, secondsToFinish As Long
    Dim xRngFind, xRng As Range
    Dim xStrg, minutesToFinish As String
    Dim currentParag, nextParag As Paragraph
    'Options.DefaultHighlightColorIndex = wdYellow
    Application.ScreenUpdating = False
    With ActiveDocument
    StartTime = Now()
    C = 0
    PC = .Paragraphs.Count
    totalComparisons = CLng((PC * (PC + 1)) / 2)
    Set currentParag = .Paragraphs(1)
    For I = 1 To PC - 1
    'Debug.Print "processing paragraph " & I & " of a total of " & PC & " " & currentParag.Range.Text
    'Debug.Print Len(currentParag) & currentParag
    If currentParag.Range.HighlightColorIndex <> wdYellow Then
    If currentParag.Range.HighlightColorIndex <> wdBrightGreen Then
    Set nextParag = currentParag
    For J = I + 1 To PC
    Set nextParag = nextParag.Next
    If currentParag.Range.Text = nextParag.Range.Text Then
    currentParag.Range.HighlightColorIndex = wdBrightGreen
    nextParag.Range.HighlightColorIndex = wdYellow
    Debug.Print "found one!! " & " I = " & I & " J = " & J & nextParag.Range.Text
    End If
    Next
    End If
    End If
    DoEvents
    comparisonsDone = PC * (I - 1) + (J - I)
    SecondsElapsed = DateDiff("s", StartTime, Now())
    secondsPerComparison = CLng(SecondsElapsed) / comparisonsDone
    secondsToFinish = CLng(secondsPerComparison * (totalComparisons - comparisonsDone))
    minutesToFinish = Format(secondsToFinish / 86400, "hh:mm:ss")
    elapsedTime = Format(SecondsElapsed / 86400, "hh:mm:ss")
    Debug.Print "Finished procesing paragraph " & I & " of " & PC & ". Elapsed time = " & elapsedTime & ". Time to finish = " & minutesToFinish
    Set currentParag = currentParag.Next
    Next
    End With
    End Sub
    • To post as a guest, your comment is unpublished.
      Emmanouil · 5 months ago
      Sir, kindly thank you and please have good winds in your life.
  • To post as a guest, your comment is unpublished.
    helin · 1 years ago
    Hello

    Thank you for the helping

    But how can I find the same sentences in my text?

    Regards
  • To post as a guest, your comment is unpublished.
    Helin · 1 years ago
    Hello

    Thank you for the helping

    But how can I find the same sentences in my text?

    Regards
  • To post as a guest, your comment is unpublished.
    Alex · 2 years ago
    It throws Compile error: Syntax error, the code is 100% as the example.
  • To post as a guest, your comment is unpublished.
    dvid · 3 years ago
    I tried, and it works fine!
    I just wanted to know - could I do the same thing - but not a whole paragraph, but a sentence with a few words I'd set up - like 10 words?
  • To post as a guest, your comment is unpublished.
    Juliana · 3 years ago
    Tentei e não funcionou, só da que parou de funcionar.