ASKER
Sub HighLightMatchingWords()
Dim docFirst As Document
Dim docSecond As Document
Dim iTarget As Integer
Dim iCount As Integer
Dim rngSent1 As Range
Dim rngSent2 As Range
Dim rngWord1 As Range
Dim rngWord2 As Range
iTarget = 6
Set docFirst = Documents.Open("C:\MyFolder\" & "First.docx")
Set docSecond = Documents.Open("C:\MyFolder\" & "Second.docx")
For Each rngSent1 In docFirst.Range.Sentences
For Each rngSent2 In docSecond.Range.Sentences
iCount = 0
For Each rngWord1 In rngSent1.Words
For Each rngWord2 In rngSent2.Words
If StrComp(rngWord1.Text, rngWord2.Text, vbTextCompare) = 0 Then
rngWord2.HighlightColorIndex = wdYellow
iCount = iCount + 1
End If
Next rngWord2
If iCount < iTarget Then
rngSent2.HighlightColorIndex = wdNoHighlight
End If
Next rngWord1
Next rngSent2
Next rngSent1
End Sub
ASKER
ASKER
Sub comparison1()
Dim doc As Document
Dim doc1 As Document
Set doc = ActiveDocument
Dim sen As Range
Dim wrd
Dim wrd1
Dim sen1 As Range
Dim SelectedFileItem As String
Dim afile
Dim item_count As Variant
Dim total_item
Dim FDialog As FileDialog
Set FDialog = Application.FileDialog(msoFileDialogOpen)
Dim c_dict As Scripting.Dictionary
Set c_dict = New Scripting.Dictionary
Dim c_dict1 As Scripting.Dictionary
Set c_dict1 = New Scripting.Dictionary
With FDialog
.Title = "Select a file"
.AllowMultiSelect = False
.InitialFileName = "D:\OneDrive - CACTUS\Documents"
.Filters.Clear
.Filters.Add "Word files", "*.docx"
If .Show = -1 Then
SelectedFileItem = .SelectedItems(1)
afile = SelectedFileItem
Else
MsgBox "You cancelled the operation"
Exit Sub
End If
Set doc1 = Documents.Open(afile)
End With
total_item = 0
For Each sen In doc1.Range.sentences
For Each wrd In sen.words
If c_dict.Exists(LCase(wrd.Text)) = False Then
With sen
If sen.words.count > 6 Then
c_dict.Add LCase(wrd.Text), LCase(wrd.Text)
End If
End With
End If
Next
For Each sen1 In doc1.Range.sentences
For Each wrd1 In sen1.words
If c_dict1.Exists(LCase(wrd1.Text)) = False Then
If sen1.words.count >= sen.words.count Then
c_dict1.Add LCase(wrd1.Text), LCase(wrd1.Text)
End If
End If
Next
For Each item_count In c_dict.Items
If c_dict1.Exists(LCase(item_count)) = True Then
total_item = total_item + 1
If total_item > 6 Then
sen1.HighlightColorIndex = wdGray25
End If
End If
Next
c_dict.RemoveAll
c_dict1.RemoveAll
Next sen1
Next sen
For Each coll In doc1.Range.sentences
If coll.HighlightColorIndex = wdGray25 Then
highlightCount = highlightCount + 1
End If
Next
MsgBox "There are (" & highlightCount & ") similar sentences" & vbCr & "Matched items: " & total_item
End Sub
Sub HighLightMatchingSentences()
Dim docFirst As Document
Dim docSecond As Document
Dim iTarget As Integer
Dim iCount As Integer
Dim rngSent1 As Range
Dim rngSent2 As Range
Dim rngWord1 As Range
Dim rngWord2 As Range
iTarget = 6
Set docFirst = Documents.Open("C:\MyFolder\" & "First.docx")
Set docSecond = Documents.Open("C:\MyFolder\" & "Second.docx")
For Each rngSent1 In docFirst.Range.Sentences
For Each rngSent2 In docSecond.Range.Sentences
iCount = 0
For Each rngWord1 In rngSent1.Words
For Each rngWord2 In rngSent2.Words
If StrComp(rngWord1.Text, rngWord2.Text, vbTextCompare) = 0 Then
iCount = iCount + 1
End If
Next rngWord2
If iCount < iTarget Then
rngSent2.HighlightColorIndex = wdYellow
End If
Next rngWord1
Next rngSent2
Next rngSent1
End Sub
ASKER
ASKER
ASKER
Sub HighLightMatchingSentences()
Dim docFirst As Document
Dim docSecond As Document
Dim iTarget As Integer
Dim iCount As Integer
Dim rngSent1 As Range
Dim rngSent2 As Range
Dim rngWord1 As Range
Dim rngWord2 As Range
iTarget = 6
Set docFirst = Documents.Open("C:\MyFolder\" & "First.docx")
Set docSecond = Documents.Open("C:\MyFolder\" & "Second.docx")
For Each rngSent1 In docFirst.Range.Sentences
For Each rngSent2 In docSecond.Range.Sentences
iCount = 0
For Each rngWord1 In rngSent1.Words
For Each rngWord2 In rngSent2.Words
If StrComp(rngWord1.Text, rngWord2.Text, vbTextCompare) = 0 Then
iCount = iCount + 1
End If
Next rngWord2
If iCount < iTarget Then
rngSent2.HighlightColorIndex = wdYellow
End If
Next rngWord1
Next rngSent2
Next rngSent1
End Sub
Sub HighLightMatchingSentences()
Dim docFirst As Document
Dim docSecond As Document
Dim iTarget As Integer
Dim iCount As Integer
Dim rngSent1 As Range
Dim rngSent2 As Range
Dim rngWord1 As Range
Dim rngWord2 As Range
iTarget = 6
Set docFirst = Documents.Open("C:\MyFolder\" & "First.docx")
Set docSecond = Documents.Open("C:\MyFolder\" & "Second.docx")
For Each rngSent1 In docFirst.Range.Sentences
For Each rngSent2 In docSecond.Range.Sentences
iCount = 0
For Each rngWord1 In rngSent1.Words
For Each rngWord2 In rngSent2.Words
If StrComp(rngWord1.Text, rngWord2.Text, vbTextCompare) = 0 Then
iCount = iCount + 1
End If
Next rngWord2
If iCount >= iTarget Then
rngSent2.HighlightColorIndex = wdYellow
End If
Next rngWord1
Next rngSent2
Next rngSent1
End Sub
ASKER
ASKER
Sub HighLightMatchingSentences1()
Dim docFirst As Document
Dim docSecond As Document
Dim iTarget As Integer
Dim iCount As Integer
Dim rngSent1 As Range
Dim rngSent2 As Range
Dim rngWord1 As Range
Dim rngWord2 As Range
iTarget = 6
Set docFirst = Documents.Open("C:\MyFolder\" & "Doc1.docx")
Set docSecond = Documents.Open("C:\MyFolder\" & "Doc2.docx")
For Each rngSent1 In docFirst.Range.Sentences
For Each rngSent2 In docSecond.Range.Sentences
iCount = 0
For Each rngWord1 In rngSent1.words
If Len(rngWord1) > 4 Then
For Each rngWord2 In rngSent2.words
If StrComp(rngWord1.Text, rngWord2.Text, vbTextCompare) = 0 Then
iCount = iCount + 1
End If
Next rngWord2
If iCount >= iTarget Then
rngSent2.HighlightColorIndex = wdYellow
End If
End If
Next rngWord1
Next rngSent2
Next rngSent1
End Sub
ASKER
ASKER
Microsoft Word is a commercial document editing program that is part of the Microsoft Office suite. It features numerous text-editing tools for creating richly formatted documents, along with tools for the use of macros in Word documents. Word's native file formats are denoted either by a .doc or .docx file extension. Plugins permitting the Windows versions of Word to read and write formats it does not natively support, such as the OpenDocument format (ODF) are available. Word can import and display images in common bitmap formats such as JPG and GIF. It can also be used to create and display simple line-art.
TRUSTED BY