StartOf Method

Microsoft Word Visual Basic

expression.StartOf(Unit, Extend)

expression    Required. An expression that returns one of the objects in the Applies To list.

Unit   Optional WdUnits. The unit by which the start position of the specified range or selection is to be moved.

WdUnits can be one of these WdUnits constants.
wdCell
wdCharacter
wdColumn
wdParagraph
wdRow
wdSection
wdSentence
wdStory
wdTable
wdWord
If expression returns a Selection object, you can also use wdLine. The default value is wdWord.

Extend   Optional WdMovement.

WdMovementType can be one of these WdMovementType constants.
wdMove
wdExtend
If you use wdMove, both ends of the range or selection are moved to the beginning of the specified unit. If you use wdExtend, the beginning of the range or selection is extended to the beginning of the specified unit. The default value is wdMove.

Remarks

If the beginning of the specified range or selection is already at the beginning of the specified unit, this method doesn't move or extend the range or selection. For example, if the selection is at the beginning of a line, the following example returns 0 (zero) and doesn't change the selection.

char = Selection.StartOf(Unit:=wdLine, Extend:=wdMove)
		

Example

This example selects the text from the insertion point to the beginning of the line. The number of characters selected is stored in charmoved.

Selection.Collapse Direction:=wdCollapseStart charmoved = Selection.StartOf(Unit:=wdLine, Extend:=wdExtend)
		

This example moves the selection to the beginning of the paragraph.

Selection.StartOf Unit:=wdParagraph, Extend:=wdMove
		

This example moves myRange to the beginning of the second sentence in the document (myRange is collapsed and positioned at the beginning of the second sentence). The example uses the Select method to show the location of myRange.

Set myRange = ActiveDocument.Sentences(2)
myRange.StartOf Unit:=wdSentence, Extend:=wdMove
myRange.Select