In Office 2000, you can edit your recorded macros and create new macros from scratch by using the Visual Basic development environment, a special utility that has its own windows, menus, and programming tools. (Word, Excel, PowerPoint, and Access all include this program, although in Access you can't use it to edit recorded macros.) In this section, you'll learn how to use the Visual Basic development environment (also called the Visual Basic Editor) to edit the InsertAddress macro. Feel free to experiment a little in this section— the skills you learn will come in handy each time you work with macros.
To edit your InsertAddress macro using Visual Basic, follow these steps:
Figure 37-1. The Visual Basic development environment allows you to create new macros and modify existing ones.
The Visual Basic development environment (Visual Basic, for short) includes a variety of programming tools to help you write, edit, test, and manage your Word macros. The most important tools to identify now are the Project Explorer window, the Properties window, and the Code window. (We'll discuss each in this chapter.) You might see these tools in a slightly different arrangement on your screen if someone else has used your computer or if your setup options were different than ours.
The Code window is a large text editing window that displays the contents of your Office macro in a programming language called Visual Basic. Each program statement in this macro follows a particular programming rule, and the trick to learning macro programming in Office is understanding the syntax principals and program logic behind each of the Visual Basic statements.
Another name for the exact spelling, order, and spacing of keywords in a macro is statement syntax.
The macro is stored in a special program code container called a subroutine, which is part of the more comprehensive container called a module. This particular subroutine is called InsertAddress, and it is delimited (or enclosed as a block of macro text) by the Sub and End Sub statements, respectively. Within the body of the subroutine, you'll see descriptive comments, which appear in green type, and the Visual Basic program statements that do the work of the macro, which appear in black type. In this macro, the Sub and End Sub statements appear in blue type, because they are special reserved words in the Visual Basic programming language called keywords.
Follow these steps to add a descriptive comment to the macro and to edit the business phone number.
Visual Basic inserts your new comment and displays it in green type. Comments are for documentation purposes only, and are not used by the macro when it runs. We recommend that you use comments as informal notes about how your macro works if you plan to share your macro with friends and work associates. (Comments are especially useful when you write complicated program statements.) Your Code window should look like this:
This simple edit will change the content of your macro each time you run it. Although we're not focusing on the exact details of the Visual Basic program statements right now, you might find it interesting to know what the words Selection and TypeText are doing in the program code. Selection is an object, or a component of the current document or application that can be programmatically controlled. The Selection object designates a particular location in your document for action— either the text block that is highlighted, or the current insertion point.
TypeText is a method, or a command that can be executed using the specified object. When the TypeText method is used with the Selection object, Word inserts the text specified at the current insertion point— exactly what your InsertAddress macro does when you run it!
You're finished editing the InsertAddress macro for now. In the next section, you'll run the macro again and save your changes to disk.