Moving Examples


Line, Start - Move the cursor to the start of the line

The following moves the start position of the Range to the start of the line.

objRange.MoveStart Unit:=wdUnits.wdLine, _ 
                   Count:=-1

The following moves to the start of the current line.

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


Line, End - Move the cursor to the end of the line

The following moves to the end of the line

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

The following moves the end of the Range to the end of the line.

objRange.MoveEnd Unit:=wdUnits.wdLine, _ 
                 Count:=1

Line, Up - Move the cursor up 3 lines

This following moves the selection up three lines.

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



Paragraph, Start - Move the cursor to the start of a paragraph




Paragraph, End - Move the cursor to the end of a paragraph

Selection.Paragraphs(1).Range.Characters(1).Select 
Selection.Collapse wdCollapseStart

The following collapses the Range and moves it to the end of the active paragraph.

objRange = ActiveDocument.Selection.Range 
lNoOfChars = objRange.MoveUntil(Cset:=Chr$(13), _
                                Count:=wdConstants.wdForward)

Paragraph, Down - Move the cursor down 2 paragraphs

The following moves the selection down two paragraphs.

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



Document, Start - Move the cursor to the start of the document

The following example moves to the start of the document.

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


Document, End - Move the cursor to the end of the document

The following moves to the end of the document.

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



Characters, 1 Backward - Move the end position of the range 1 character backward

The following moves the end of the Range one character backward, the range is reduced by one character.

objRange.MoveEnd Unit:=wdUnits.wdCharacter, _ 
                 Count:=-1


Characters, 1 Forward - Move the start position of the range 1 character forward

The following moves the start position of the Range one character forward (the selection size is reduced by one character).

objRange.MoveStart Unit:=wdUnits.wdCharacter, _ 
                   Count:=1


Words,2 Left - Move the selection 2 words to the left

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

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





The following collapses the Range and moves it forward through the next 100 characters in the document until the character "t" is found.

Set objRange = ActiveDocument.Words(1) 
objRange.MoveUntil Cset:="t", _
                   Count:=100


The following collapses the Range and moves it over any consecutive tabs.

objRange.MoveWhile Cset:=wdUnits.vbTab, _ 
                   Count:=wdConstants.wdForward

The following collapses the Range and moves it past any of the following characters "a", "t" or "h" (uppercase or lowercase)

Set objRange = ActiveDocument.Characters(1) 
objRange.MoveWhile Cset:="atiATI", _
                   Count:=wdConstants.wdForward

The following moves the start position backwards until a capital "I" is found.
When the movement is backwards, the Range is expanded.

Selection.MoveStartUntil Cset:="I", _ 
                         Count:=wdConstants.wdBackward

The following moves the start position forwards until a "%" characters is found or for a maximum of ten 10.
When the movement is forwards, the Range is reduced.

Selection.MoveStartUntil Cset:="%", _ 
                         Count:=10




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