J
John Kaurloto
To the group:
I want to loop through a document comparing sequential sentences. The code
is below.
To test this I have copied and pasted sentences so sentences one and two are
exact and four and five are exact, yet I continually get a 'They Match'
message box through the entire document (thirteen sentences in the test
document).
What am I doing wrong?
Thank you in advance for any assistance or suggestions.
John Kaurloto
Sub SbyS()
Dim x As Integer
Dim s1 As Object
Dim s2 As Object
' Move the insertion point to the beginning of the document.
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
' Loop number of sentences in document.
x = ActiveDocument.Sentences.Count
For i = 1 To x
' Select a sentence.
ActiveDocument.Sentences(i).Select
Set s1 = Selection
' Move to next sentence.
ActiveDocument.Sentences(i + 1).Select
Set s2 = Selection
'compare sentences
If s1.IsEqual(s2.Range) = True Then
MsgBox "They Match"
Else
MsgBox "No Match"
End If
Next i
End Sub
I want to loop through a document comparing sequential sentences. The code
is below.
To test this I have copied and pasted sentences so sentences one and two are
exact and four and five are exact, yet I continually get a 'They Match'
message box through the entire document (thirteen sentences in the test
document).
What am I doing wrong?
Thank you in advance for any assistance or suggestions.
John Kaurloto
Sub SbyS()
Dim x As Integer
Dim s1 As Object
Dim s2 As Object
' Move the insertion point to the beginning of the document.
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
' Loop number of sentences in document.
x = ActiveDocument.Sentences.Count
For i = 1 To x
' Select a sentence.
ActiveDocument.Sentences(i).Select
Set s1 = Selection
' Move to next sentence.
ActiveDocument.Sentences(i + 1).Select
Set s2 = Selection
'compare sentences
If s1.IsEqual(s2.Range) = True Then
MsgBox "They Match"
Else
MsgBox "No Match"
End If
Next i
End Sub