Share this Page URL

The VBA Editor in Word > The Object Browser - Pg. 437

You can run this code by placing the cursor in the procedure's body and hitting F5, the Run Sub/UserForm toolbar button, or -- for this particular example -- by cre- ating a new document and choosing as its template. You should see a mes- sage box pop up and display the message text. That's really all there is to writing code in the VBA editor, though procedures are usually considerably more complex than this example (see the UserForm code at the end of this chapter for some more complex examples of Word VBA code). If you want to get serious about VBA customizations to Word, you'll want to explore de- bugging and other helpful features of the editor. The Object Browser While you can certainly use the online help (accessed by the Help menu or F1) provided in the VBA editor to explore Word's object model, there is an alternative. The editor has a built-in tool called the Object Browser that lets you see the Word VBA objects and their methods, properties, and events. To access the object browser, select Tools Object Browser, hit F2, or click the Object Browser button on the toolbar. The screen in Figure 18-9 overlays the code window (though it can be docked if you wish, by checking Immediate Window on the Docking page of the Options dialog opened from the VBA window). Choose which library of objects is displayed in the browser by selecting one from the Libraries drop-down box at the top of the window. Here, I've chosen the Word object library.