PDA

View Full Version : Five word comparison of a text with whole Document



asad111
01-26-2018, 04:00 AM
I did Five-Word compassion of a text in a Text-box with a Document. Following codes find text and highlight it if found in Document.

These are successful codes I wrote sometime ago. It is only to share these codes. Anyone can benefit from them or add better suggestion.



Dim a, b, c, e, f, g As Integer, d As StringDim Rng As Word.Range


Private Sub CommandButton1_Click()


Open "D:\List.txt" For Output As #1


Set Rng = ActiveDocument.Content


a = 0
For n = 0 To 20000


Set Rng = ActiveDocument.Content


b = InStr(a + 1, Text1.Text, " ")
If b = 0 Then End
b = b + 1
b = InStr(b, Text1.Text, " ")
If b = 0 Then End
b = b + 1
b = InStr(b, Text1.Text, " ")
If b = 0 Then End
b = b + 1
b = InStr(b, Text1.Text, " ")
If b = 0 Then End
b = b + 1
b = InStr(b, Text1.Text, " ")
If b = 0 Then End
c = b


Text1.SelStart = a
Text1.SelLength = c - a - 1
a = c
ResetFRParameters Rng
Rng.Find.ClearFormatting


With Rng.Find

While .Execute(FindText:=Text1.SelText, Forward:=True, Wrap:=wdFindStop)
If .Found = True Then
Rng.HighlightColorIndex = wdYellow
Print #1, Text1.SelText
End If
Wend

End With




Next
Close
End Sub


Sub ResetFRParameters(Rng As Range)
With Rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub