Chapter 18. Working with VBA

In previous chapters, you’ve seen how Word’s look, feel, and general operations can be customized to suit your own style. This capability is a powerful aspect of using Word, but you’re not limited to tweaking menus and toolbars.

This chapter provides an overview of using macros and Visual Basic for Applications (VBA) to push Word beyond its normal boundaries. It starts with a quick introduction to recording and running macros, then moves into a discussion of the VBA environment. The chapter includes:

  • A language primer that examines the basic syntax and structure of VBA, including various constructs like statements, comments, variables, and constants.

  • An overview of the Word object model, the hierarchy of related objects that represent almost all of the components of the Word interface. Word objects are used to retrieve information, create new items, and cause Word to perform actions.

  • A look at Word’s VBA Editor, the development environment used to write, test, and organize code.

  • An examination of user forms, which are used to gather input from a user at runtime.

Note

If what you see in this chapter whets your appetite, you can find a more complete treatment of Word programming in Writing Word Macros, by Steven Roman (O’Reilly & Associates). For more on general VBA programming, take a look at VB & VBA in a Nutshell, by Paul Lomax (O’Reilly & Associates).

Extending Word

There are several ways to enhance and extend the capabilities of Word:

Record a macro (Tools ...

Get Word 2000 in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.