Share via


TextRange.compareEndPoints Method

SharePoint Designer Developer Reference

Compares an end point of an TextRange object with an end point of another TextRange object. Returns a Long that represents the comparison of the specified points.

Syntax

expression.compareEndPoints(how, SourceRange)

expression   Required. A variable that represents an TextRange object.

Parameters

Name Required/Optional Data Type Description
how Required String String. Specifies how the two TextRange objects are to be compared. May be one of the following four values.
Value Description
StartToStart
Compares the start of the specified TextRange object with the start of the TextRange object specified in the SourceRange parameter.
StartToEnd
Compares the start of the specified TextRange object with the end of the TextRange object specified in the SourceRange parameter.
EndToStart
Compares the end of the specified TextRange object with the start of the TextRange object specified in the SourceRange parameter.
EndToEnd
Compares the end of the specified TextRange object with the end of the TextRange object specified in the SourceRange parameter.
SourceRange Required TextRange The range with which to compare the initial range specified.

Remarks

The Long value returned for the compareEndPoints method can be one of the following values.

Value Description
-1 The end point of the object is to the right of the end point of the TextRange object specified in the SourceRange parameter.
0 The end point of the object is at the same location as the end point of of the TextRange object specified in the SourceRange parameter.
1 The end point of the object is to the left of the end point of of the TextRange object specified in the SourceRange parameter.

Example

The following example compares the selected range with the document and displays a message stating whether the selected range is at the beginning of the document or the end of the document.

Visual Basic for Applications
Sub CompareTwoRanges()
    Dim objDoc As TextRange
    Dim objRange As TextRange
    
    Set objDoc = ActiveDocument.body.createTextRange
    Set objRange = ActiveDocument.Selection.createRange
    
    If objRange.compareEndPoints("endtoend", objDoc) = 0 Then
        MsgBox "The selected text is at the end of the page."
    ElseIf objRange.compareEndPoints("starttostart", objDoc) = 0 Then
        MsgBox "The selected text is at the beginning of the page."
    Else
        MsgBox "The selected text is in the middle of the page."
    End If
End Sub

See Also