20.3. Working with the Selection Object

To perform actions on part of a document using VBA, you can access that zone in three ways:

  • By using the Selection object

  • By directly accessing the object that you want to affect

  • By defining a range that encompasses the object.

Using the Selection object is analogous to working interactively with Word and works well with procedures that require the user to select an object or position the insertion point to denote what the procedure should affect.

Using the Selection object is also effective when you're learning to use VBA with Word, because many actions that you record using the Macro Recorder use the Selection object.

The Selection object represents the current selection in the active document in Word. ...

Get Mastering VBA for Microsoft Office 2007, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.