IsEqual Method

Microsoft Word Visual Basic

True if the selection or range to which this method is applied is equal to the range specified by the Range argument. This method compares the starting and ending character positions, as well as the story type. If all three of these items are the same for both objects, the objects are equal.

expression.IsEqual(Range)

expression    Required. An expression that returns a Range or Selection object.

Range    Required Range object. The Range object that's compared with expression   .

Example

This example compares the selection with the second paragraph in the active document. If the selection isn't equal to the second paragraph, the second paragraph is selected.

If Selection.IsEqual(ActiveDocument _
        .Paragraphs(2).Range) = False Then
    ActiveDocument.Paragraphs(2).Range.Select
End If
		

This example compares Range1 with Range2 to determine whether they're equal. If the two ranges are equal, the content of Range1 is deleted.

Set Range1 = Selection.Words(1)
Set Range2 = ActiveDocument.Words(3)
If Range1.IsEqual(Range:=Range2) = True Then
    Range1.Delete
End If