MoveEnd Method

Moves the ending character position of a range or selection. This method returns an integer that indicates the number of units the range or selection actually moved, or it returns 0 (zero) if the move was unsuccessful.

expression**.MoveEnd(Unit**, Count)

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

WdUnits

Can be one of the following WdUnits constants

wdCharacter

wdWord

wdSentence

wdParagraph

wdSection

wdStory

wdCell

wdColumn

wdRow

wdTable.

If expression returns a Selection object, wdLine can also be used. The default value is wdCharacter.

Count    Optional Variant. The number of units to move. If this number is positive, the ending character position is moved forward in the document. If this number is negative, the end is moved backward. If the ending position overtakes the starting position, the range collapses and both character positions move together. The default value is 1.

Example

This example moves the end of the selection one character backward (the selection size is reduced by one character). A space is considered a character.

Selection.MoveEnd Unit:=wdCharacter, Count:=-1

This example moves the end of the selection to the end of the line (the selection is extended to the end of the line).

Selection.MoveEnd Unit:=wdLine, Count:=1

This example sets myRange to be equal to the second word in the active document. The MoveEnd method is used to move the ending position of myRange (a range object) forward one word. After this macro is run, the second and third words in the document are selected.

If ActiveDocument.Words.Count >= 3 Then
    Set myRange = ActiveDocument.Words(2)
    With myRange
        .MoveEnd Unit:=wdWord, Count:=1
        .Select
    End With
End If

Applies to | Range Object | Selection Object

See Also | EndOf Method | Move Method | MoveEndUntil Method | MoveEndWhile Method | MoveStart Method