Share via


Move Method

Move method as it applies to the Range and Selection objects.

Collapses the specified range or selection to its start or end position and then moves the collapsed object by the specified number of units. This method returns a Long value that indicates the number of units by which the object was actually moved, or it returns 0 (zero) if the move was unsuccessful.

expression.Move(Unit, Count)

expression Required. An expression that returns one of the above objects.

Unit   Optional Variant. The unit by which the collapsed range or selection is to be moved. Can be one of the following WdUnits constants: wdCharacter, wdWord, wdSentence, wdParagraph, wdSection, wdStory, wdCell, wdColumn, wdRow, or wdTable. If expression returns a Selection object, you can also use wdLine. The default value is wdCharacter.

Count   Optional Variant. The number of units by which the specified range or selection is to be moved. If Count is a positive number, the object is collapsed to its end position and moved backward in the document by the specified number of units. If Count is a negative number, the object is collapsed to its start position and moved forward by the specified number of units. The default value is 1. You can also control the collapse direction by using the Collapse method before using the Move method. If the range or selection 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.

Remarks

The start and end positions of a collapsed range or selection are equal.

Applying the Move method to a range doesn't rearrange text in the document. Instead, it redefines the range to refer to a new location in the document.

If you apply the Move method to any range other than a Range object variable (for example, Selection.Paragraphs(3).Range.Move), the method has no effect.

Moving a Selection object collapses the selection and moves the insertion point either forward or backward in the document.

Move method as it applies to the Application and Task objects.

Positions a task window or the active document window.

expression.Move(Left, Top)

expression Required. An expression that returns one of the above objects.

Left   Required Long. The horizontal screen position of the specified window.

Top   Required Long. The vertical screen position of the specified window.

Move method as it applies to the StyleSheet object.

Moves a style sheet's order of precedence.

expression.Move(Precedence)

expression Required. An expression that returns a StyleSheet object.

WdStyleSheetPrecedence

WdStyleSheetPrecedence can be one of these WdStyleSheetPrecedence constants.
wdStyleSheetPrecedenceHigher
wdStyleSheetPrecedenceHighest
wdStyleSheetPrecedenceLower
wdStyleSheetPrecedenceLowest

Example

As it applies to the Application object.

This example starts the Calculator application (Calc.exe) and uses the Move method to reposition the application window.

Shell "Calc.exe"
With Tasks("Calculator")
    .WindowState = wdWindowStateNormal
    .Move Top:=50, Left:=50
End With

As it applies to the Range object.

This example sets Range1 to the first paragraph in the active document and then moves the range forward three paragraphs. After this macro is run, the insertion point is positioned at the beginning of the fourth paragraph.

Set Range1 = ActiveDocument.Paragraphs(1).Range
With Range1
    .Collapse Direction:=wdCollapseStart
    .Move Unit:=wdParagraph, Count:=3
    .Select
End With

As it applies to the Selection object.

This example moves the selection two words to the right and positions the insertion point after the second word's trailing space. If the move is unsuccessful, a message box indicates that the selection is at the end of the document.

If Selection.StoryType = wdMainTextStory Then
    wUnits = Selection.Move(Unit:=wdWord, Count:=2)
    If wUnits < 2 Then _
        MsgBox "Selection is at the end of the document"
End If

This example moves the selection forward three cells in the table.

If Selection.Information(wdWithInTable) = True Then
    Selection.Move Unit:=wdCell, Count:=3
End If

Applies to | Application Object | Range Object | Selection Object | StyleSheet Object | Task Object

See Also | GoTo Method | MoveDown Method | MoveEnd Method | MoveLeft Method | MoveRight Method | MoveStart Method | MoveUp Method | StartOf Method