Selection Object - Extending


Extend

Turns extend mode on (sets the ExtendMode property to True), or if extend mode is already on, extends the Selection object to the next larger unit of text.
The progression of selected units of text is as follows: word, sentence, paragraph, section, entire document.

objSelection.Extend(Character:="A") 

Character - The character through which the selection is extended. This argument is case sensitive and must evaluate to a String or an error occurs. Also, if the value of this argument is longer than a single character, the command is ignored.


This example collapses the current selection to an insertion point and then selects the current sentence.

With Selection 
' Collapse current selection to insertion point.
    .Collapse
' Turn extend mode on.
    .Extend
' Extend selection to word.
    .Extend
' Extend selection to sentence.
    .Extend
End With

Here is an example that accomplishes the same task without the Extend method.

With Selection 
' Collapse current selection.
    .Collapse
' Expand selection to current sentence.
    .Expand Unit:=wdUnits.wdSentence
End With

This example makes the end of the selection active and extends the selection through the next instance of a capital "R".

With Selection 
    .StartIsActive = False
    .Extend Character:="R"
End With

ExtendMode

This property is True when the Extend mode is active.
This property can only be set during run time; attempts to set it in Immediate mode are ignored. The Extend arguments of the EndOf and StartOf methods are not affected by this property.


This example moves to the beginning of the paragraph and selects the paragraph plus the next two sentences.

With Selection 
    .MoveLeft Unit:=wdUnits.wdCharacter, Count:=4, Extend:=True
    .MoveRight Unit:=wdUnits.wdSentence, Count:=2
    .ExtendMode = True
    .MoveUp Unit:=wdUnits.wdParagraph
    .MoveDown Unit:=wdUnits.wdParagraph
End With

This example collapses the current selection, turns on Extend mode, and selects the current sentence.

With Selection 
    .Collapse
    .ExtendMode = True
' Select current word.
    .Extend
' Select current sentence.
    .Extend
End With


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