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

or

Hoe vind en markeer ik dubbele alinea's in een Word-document?

Stel dat u een groot Word-document heeft dat honderden pagina's kan bevatten, nu wilt u controleren of er dubbele alinea's zijn en vervolgens markeren om ze te laten opvallen, zodat u de dubbele zinnen kunt verwerken. Hoe kon je de dubbele alinea's snel en gemakkelijk in een Word-document vinden en markeren?

Zoek en markeer de dubbele alinea's in Word-document met VBA-code


Zoek en markeer de dubbele alinea's in Word-document met VBA-code

Om de dubbele alinea's in een Word-document te vinden en te markeren, kan de volgende VBA-code u een plezier doen, doe dit als volgt:

1. Houd de ALT + F11 toetsen om de te openen Microsoft Visual Basic voor toepassingen venster.

2. En klik dan Invoegen > Module, kopieer en plak onderstaande code in de geopende lege module:

VBA-code: zoek en markeer de dubbele alinea's in Word-document:

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. En druk vervolgens op F5 sleutel om deze code uit te voeren, alle dubbele zinnen worden tegelijk gemarkeerd, de eerste weergegeven dubbele alinea's worden gemarkeerd met een groene kleur en andere duplicaten worden gemarkeerd met een gele kleur, zie screenshot:

doc markeer dup zinnen 1


Aanbevolen Word-productiviteitstools

 

Kutools For Word - Meer dan 100 geavanceerde functies voor Word, bespaar 50% tijd

  • Ingewikkelde en herhaalde bewerkingen kunnen een eenmalige verwerking in seconden worden uitgevoerd.
  • Voeg meerdere afbeeldingen in verschillende mappen tegelijk in een Word-document in.
  • Voeg meerdere Word-bestanden in mappen samen en combineer ze tot één met de door u gewenste volgorde.
  • Splits het huidige document in afzonderlijke documenten op basis van koptekst, sectie-einde of andere criteria.
  • Converteer bestanden tussen Doc en Docx, Docx en PDF, verzameling tools voor algemene conversies en selectie, enzovoort ...
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.
    Harsh · 4 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 · 5 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 · 2 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.