Moving


Range.Move (collapse before)

Range objects include non printing characters such as spaces, tab characters and paragraph marks !!
Collapses the Range or Selection object to its start or end position (referring to an insertion point) and then moves the Range the specified number of units.
This method returns a value (Long) that indicates the number of units by which the start position has actually moved.
If it returns zero (0) then the move was unsuccessful.

lNoOfChars = objRange.Move(Unit:=wdUnits.wdParagraph, _ 
                           Count:=1)

Unit - The unit can only be one of the wdUnits enumerations. The default is wdCharacter.
You can only use wdLine when using a Selection object.
Count - The number of units to move. The default value is 1.
If Count is positive, the Range object is collapsed to its end position and moved forward.
If Count is negative, the Range object is collapsed to its start position and moved backward.


objRange.Move(Unit:=wdUnits.wdCell) 
objRange.Move(Unit:=wdUnits.wdCharacter)
objRange.Move(Unit:=wdUnits.wdColumn)
objRange.Move(Unit:=wdUnits.wdParagraph)
objRange.Move(Unit:=wdUnits.wdRow)
objRange.Move(Unit:=wdUnits.wdSentence)
objRange.Move(Unit:=wdUnits.wdSection)
objRange.Move(Unit:=wdUnits.wdStory)
objRange.Move(Unit:=wdUnits.wdTable)
objRange.Move(Unit:=wdUnits.wdWord)

Using any other unit will generate a Bad Paramater error.
You can also control the collapse direction by using the Collapse method before using the Move method.
If the range is in the middle of a unit or isn't collapsed, moving it to the beginning or end of the unit counts as moving it one full unit.


Range.MoveStart

Moves the start position of the Range or Selection object a specified number of units.
This method returns a value (Long) that indicates the number of units by which the start position has actually moved.
If it returns zero (0) then the move was unsuccessful.

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

Unit - The unit can only be one of the wdUnits enumerations. The default is wdCharacter.
You can only use wdLine when using a Selection object.
Count - The number of characters to move. The default is 1.


Range.MoveEnd

Moves the end position of the Range or Selection object a specified number of units.
This method returns the number of units by which the start position has moved.
If it returns zero (0) then the move was unsuccessful.

lNoOfChars = objRange.MoveEnd(Unit:=wdUnits.wdCharacter, _ 
                              Count:=1)

Unit - The unit can only be one of the wdUnits enumerations. The default is wdCharacter.
You can only use wdLine when using a Selection object.
Count - The number of units to move. The default is 1.


Range.MoveUntil (collapse before)

Collapses the Range or Selection object to an insertion point and moves it infront of the first specified character.
This method returns a value (Long) that indicates the number of units by which the Range has actually moved.

lNoOfChars = objRange.MoveUntil(Cset:=  , _ 
                                Count:=1

Cset - One or more characters. This argument is case sensitive.
Count - The maximum number of characters to move. Can also be the wdForward or wdBackward constant. The default value is wdForward.
If Count is positive, the Range is moved forward (starting at the end position).
If Count is negative, the Range is moved backward (starting at the start position).
If Count is greater than 0 (zero), this method returns the number of characters moved plus 1.
If Count is less than 0 (zero), this method returns the number of characters moved minus 1.
If none of the characters are found the method returns zero (0) and the Range is not changed.


Range.MoveWhile (collapse before)

Collapses the Range or Selection object to an insertion point and moves it infront of the characters while any of the specified characters are found.
This method returns a value (Long) that indicates the number of units by which the Range has actually moved.

lNoOfChars = objRange.MoveWhile(Cset:=  , _ 
                                Count:=1

Cset - One or more characters. This argument is case sensitive.
Count - The maximum number of characters to move. Can also be the wdForward or wdBackward constant. The default value is wdForward.
If Count is a positive, the Range is moved forward (starting at the end position).
If Count is negative, the Range is moved backward (starting at the start position).
If Count is greater than 0 (zero), this method returns the number of characters moved plus 1.
If Count is less than 0 (zero), this method returns the number of characters moved minus 1.
If none of the characters are found the method returns zero (0) and the Range is not changed.


Range.MoveStartUntil

Moves the start position of the Range or Selection object until one of the specified characters is found.
This method returns the number (Long) of characters that the start position has moved.

lNoOfChars = objRange.MoveStartUntil(Cset:=  , _ 
                                     Count:=1

Cset - One or more characters. This argument is case sensitive.
Count - The maximum number of characters to move. Can also be the wdForward or wdBackward constant. If Count is a positive, the Range is moved forward. If Count is negative, the Range is moved backward. The default value is wdForward.
If Count is greater than 0 (zero), this method returns the number of characters moved plus 1.
If Count is less than 0 (zero), this method returns the number of characters moved minus 1.
If none of the characters are found the method returns zero (0) and the Range is not changed.
If the start position is moved forward to a point beyond the end position, the Range is collapsed and both the start and end positions are moved together.


Range.MoveEndUntil

Moves the end position of the Range or Selection object until one of the specified characters is found.
This method returns the number (Long) of characters that the end position has moved.

lNoOfChars = objRange.MoveEndUntil(Cset:=  , _ 
                                   Count:=1

Cset - One or more characters. This argument is case sensitive.
Count - The maximum number of characters to move. Can also be the wdForward or wdBackward constant.
If Count is a positive, the Range is moved forward. If Count is negative, the Range is moved backward. The default value is wdForward.
If the movement is forwards then then the Range is expanded.


Range.MoveStartWhile

Moves the start position of the Range or Selection object while any of the specified characters are found.
This method returns the number (Long) of characters that the start position has moved.

objRange.MoveStartWhile(Cset:=  , _ 
                        Count:=1)

Cset - One or more characters. This argument is case sensitive.
Count - The maximum number of characters to move. Can also be the wdForward or wdBackward constant.
If Count is a positive, the Range is moved forward. If Count is negative, the Range is moved backward. The default value is wdForward.
If none of the characters are found then the Range does not change.


Range.MoveEndWhile

Moves the end position of the Range or Selection object while any of the specified characters are found.
This method returns the number (Long) of characters that the end position has moved.

objRange.MoveEndWhile(Cset:=  , _ 
                      Count:=1)

Cset - One or more characters. This argument is case sensitive.
Count - The maximum number of characters to move. Can also be the wdForward or wdBackward constant.
If Count is a positive, the Range is moved forward. If Count is negative, the Range is moved backward. The default value is wdForward.


Selection.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.


Selection.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.


Selection.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 unit can be either wdLine, wdParagraph, wdWindow, wdScreen. The default value is wdLine.
Count - The number of units to move. The default is 1.
Extend - The default is wdMove.


Selection.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)

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


Selection.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)

Selection.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)

Selection.

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

Selection.Move 
Selection.MoveUntil
Selection.MoveWhile
Selection.MoveStart
Selection.MoveStartUntil
Selection.MoveStartWhile
Selection.MoveEnd
Selection.MoveEndUntil
Selection.MoveEndWhile


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