Chapter 6

Inserting and Manipulating Content

When you use Microsoft Office applications like Word, Excel, and PowerPoint, your most common task is to specify an area in a document and then manipulate the content. The content you insert and manipulate can be of any type, such as text, tables, charts, and shapes. The formatting you apply generally consists of font, border, and fill attributes. Using the mouse pointer or keyboard, you scroll in the document to search visually for an area that you then manipulate with menu and toolbar commands.

Using Microsoft Visual Basic for Applications, you write code to do what you did visually: locate an area in the document and manipulate the content with methods and properties in the object model. The difference with using Visual Basic code is that you can locate and manipulate content without changing what's displayed on the user's screen. You can choose to write your code so that content manipulation occurs:

This chapter tells you how to use Visual Basic code to locate a specific area in a document and create and manipulate content such as text, tables, charts, and shapes in that area. It also describes common differences between object model members that manipulate similar content types, such as text.

In Chapters 7 and 8, you'll learn how to create instances of an Office application behind the scenes and create content without having to show the applications. In Chapter 10, you'll learn how to write code that identifies for you, based on events from the keyboard and mouse, what content the user interacts with. Based on this information, you can perform actions such as updating custom toolbars and displaying custom menus and shortcut menus.

TIP
This chapter describes the most common elements of handling content in Word, Excel, and PowerPoint. It also compares the ways in which common content elements (such as text) are different in Word, Excel, and PowerPoint. If you want to quickly see the methods and properties that Word, Excel, and PowerPoint use to insert and manipulate content, use the Macro Recorder.

Chapter 1 outlines the use of the Macro Recorder. It's highly recommended as the fastest way to learn the methods and properties required to insert and manipulate content. In several cases, the examples in this chapter were generated from the Macro Recorder and then modified for style.

Also, when the Word, Excel, or PowerPoint Visual Basic Editor is active, use the online help by pressing F1 to get more information about specific methods and properties used in this chapter. If the Office Assistant is displayed, type 'Working with Range objects' in the text box in its balloon. If the Help window is displayed, type the same thing in the Answer Wizard tab's text box.