Editing Text
Word Developer Reference |
This topic includes Microsoft Visual Basic examples related to the following tasks:
- Determining whether text is selected
- Collapsing a selection or range
- Extending a selection or range
- Redefining a selection or range
- Changing text
For information about, and examples of, other editing tasks, see the following topics:
Returning text from a document
Manipulating a portion of a document
Determining whether text is selected
The Type property of the Selection object returns information about the type of selection. The following example displays a message if the selection is an insertion point.
|
Collapsing a selection or range
Use the Collapse method to collapse a Selection object or a Range object to its beginning or ending point. The following example collapses the selection to an insertion point at the beginning of the selection.
|
The following example cancels the range to its ending point (after the first word) and adds new text.
|
Extending a selection or range
The following example uses the MoveEnd method of the Selection object to extend the end of the selection to include three additional words. The MoveLeft, MoveRight, MoveUp, and MoveDown methods can also be used to extend a Selection object.
|
The following example uses the MoveEnd method of the Range object to extend the range to include the first three paragraphs in the active document.
|
Redefining a selection or range
Use the SetRange method to redefine an existing Selection object or Range object. For more information, see Working with the Selection object or Working with Range objects.
Changing text
You can change existing text by changing the contents of a range. The following instruction changes the first word in the active document by setting the Text property of a Range object to "The ".
|
You can also use the Delete method or the Selection object or the Range object to delete existing text, and then insert new text using the InsertAfter method or the InsertBefore method. The following example deletes the first paragraph in the active document and inserts new text.
|