Working with Document Content
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
When you have a document to work with, most of the tasks you'll want to perform with VBA will involve working with the text in the document or manipulating the objects contained in the document. Documents contain words, sentences, paragraphs, sections, headers and footers, tables, fields, controls, images, shapes, hyperlinks and more. All of these objects are available to you through VBA.
The starting point for much of what you do to the contents of a document will be to specify a part of the document and then to do something to it. This might involve, for example, adding or removing text or formatting words or characters. The two objects you will use to accomplish much of this work are the Range object and the Selection object.
In This Section
- The Range Object
Understand the Range object, including creating, defining, determining the location of, and working with text in a Range object. - The Selection Object
Learn about the Selection object, including how to use its Type property to get information about the state of the current selection. - The Selection Object vs. the Range Object
Compare and contrast the Selection and Range objects. - Working with Bookmarks
Use bookmarks to mark a location in a document or as a container for text in a document. - The Find and Replacement Objects
Loop through a document looking for some specific text, formatting, or style, and specify what you want to use to replace the item you found.
Related Sections
- Working with Microsoft Word Objects
Use VBA to work with the Microsoft® Word Document object, Application object, and Documents collection. - Understanding Application-Level Objects
Learn about the Application object and other objects that affect Word. - The Document Object
Create or open documents and add them to the Documents collection.