Selection Object - Moving

The following methods also exist for a Selection:
Move, MoveStart, MoveEnd, MoveUntil, MoveWhile, MoveStartUntil, MoveEndUntil, MoveStartWhile, MoveEndWhile


HomeKey

Moves the Selection object to the beginning of the specified unit.

lNoOfChars = objSelection.HomeKey(Unit:=wdUnits.wdStory, _ 
                                  Extend:=wdMovementType.wdMove)

Unit -
Extend - The default is wdMove.
This method returns a value (Long) that indicates the number of characters the selection has actually moved.
If it returns zero (0) then the moved was unsuccessful.
The following example moves to the beginning of the document.

objSelection.HomeKey(Unit:=wdUnits.wdStory, _ 
                     Extend:=wdMovementType.wdMove)

The following moves to the beginning of the current line.

objSelection.HomeKey(Unit:=wdUnits.wdLine, _ 
                     Extend:=wdMovementType.wdMove)

EndKey

Moves the Selection object to the end of the specified unit.

lNoOfChars = objSelection.EndKey(Unit:=wdUnits.wdStory, _ 
                                 Extend:=wdMovementType.wdMove)

Unit -
Extend - The default is wdMove.


This method returns a value (Long) that indicates the number of characters the selection has actually moved.
If it returns zero (0) then the moved was unsuccessful.
The following moves to the end of the document.

objSelection.EndKey(Unit:=wdUnits.wdStory, _ 
                    Extend:=wdMovementType.wdMove)

The following moves to the end of the line

objSelection.EndKey(Unit:=wdUnits.wdLine, _ 
                    Extend:=wdMovementType.wdMove)


MoveUp

Moves the Selection object up and returns the number of units it has moved.
The current selection is collapsed to the end point before being moved up.
The wdWindow constant can also be used to move to the top of the current screen.
The wdScreen constant can also be used to move more than one screen.

lNoOfChars = objSelection.MoveUp(Unit:=wdUnits.wdParagraph, _ 
                                 Count:=1, _
                                 Extend:=wdMovementType.wdMove)

Unit - The default value is wdLine. The unit can be either wdLine, wdParagraph, WdWindow, wdScreen
Count - The number of units to move. The default is 1.
Extend - The default is wdMove.


This following moves the selection up three lines.

objSelection.MoveUp(Unit:=wdUnits.wdLine, _ 
                  Count:=3, _
                  Extend:=wdMovementType.wdMove)

MoveDown

Moves the Selection object down and returns the number of units it has moved.
The current selection is collapsed to the end point before being moved up.
The wdWindow constant can also be used to move to the top of the current screen.
The wdScreen constant can also be used to move more than one screen.

lNoOfChars = objSelection.MoveDown(Unit:=wdUnits.wdParagraph, _ 
                                   Count:=1, _
                                   Extend:=wdMovementType.wdMove)

The following moves the selection down two paragraphs.

objSelection.MoveDown(Unit:=wdUnits.wdParagraph, _ 
                      Count:=2, _
                      Extend:=wdMovementType.wdMove)

MoveLeft

Moves the Selection object to the left and returns the number of units it has moved.
The current Selection object is collapsed to the end point before being moved left.

lNoOfChars = objSelection.MoveLeft(Unit:=wdUnits.wdCharacters, _ 
                                   Count:=1, _
                                   Extend:=wdMovementType.wdMove)

The following moves the Selection object two words to the left.

objSelection.MoveLeft(Unit:=wdUnits.wdWords, _ 
                      Count:=2, _
                      Extend:=wdMovementType.wdMove)

MoveRight

Moves the Selection object to the right and returns the number of units it has moved.
The current Selection object is collapsed to the end point before being moved right.

lNoOfChars = objSelection.MoveRight(Unit:=wdUnits.wdCharacters, _ 
                                    Count:=1, _
                                    Extend:=wdMovementType.wdMove)

The following moves the Selection object two words to the left.

objSelection.MoveLeft(Unit:=wdUnits.wdWords, _ 
                      Count:=2, _
                      Extend:=wdMovementType.wdMove)

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext