Hi guys, I am new to vba and I am trying to learn it. I am a writer and i want to create a vba that compares two paragraphs for duplication. If duplication if found the sentence being duplicated will be highligted into different colors, example i found 5 duplicate, i want to see also five colors in the output so that i can easily count the number of duplicated sentence fragments or phrases. I found a code that do exactly what i need only that it cannot set a lenght of matching parts and it has only two colors for highlighting duplicates. I created a userform that contains 2 rich texbox, the first box is for the source and the second box is for the article to be compared in the source. I also put a command button "Compare". I also put a combo box so that i can select the minimum lenght of matching part. Below is the code i found:
[vba]
Sub Compare()
Const NMin As Long = 7
Dim R As Range, W As Range
Dim C As Range, C2 As Range, N As Long
Set R = ActiveDocument.Content
For Each W In R.Words
If W.HighlightColorIndex = wdNoHighlight Then
N = NMin
Do
Set C = W.Duplicate
C.MoveEnd wdWord, N
If C.End = ActiveDocument.Range.End Then Exit Sub
Set C2 = ActiveDocument.Range(C.End, ActiveDocument.Range.End)
Select Case True
Case Len(C.Text) > 256, _
C.HighlightColorIndex = 9999999, _
C2.Find.Execute(FindText:=C.Text, Wrap:=wdFindStop) = False
If N > NMin Then DoHighLight C
Exit Do
Case Else
N = N + 1
End Select
Loop
End If
Next
End Sub
Sub DoHighLight(C As Range)
Dim C2 As Range
C.MoveEnd wdWord, -1
C.HighlightColorIndex = wdYellow
Set C2 = ActiveDocument.Range(C.End, ActiveDocument.Range.End)
While C2.Find.Execute(FindText:=C.Text, Wrap:=wdFindStop)
C2.HighlightColorIndex = wdRed
Wend
End Sub
Public Sub Show()
frmMain.Show
End Sub
[/vba]
Now my question is how can I integrate this code into my own modified format. Please see attached file.
Hope you can spare time on my problem.
Thank you so much.
Credits to Tony Jollans for the code.