Organization of This Book

Writing Word Macros consists of 21 chapters divided into three parts. In addition, there are four appendixes.

Chapter 1, Introduction, examines why you might want to learn programming, and provides a few examples of the sorts of problems that can best be solved through programming.

Chapter 2, Preliminaries, introduces the Visual Basic for Applications language. Chapters Chapter 3 and Chapter 4, The Visual Basic Editor, Part I and The Visual Basic Editor, Part II, examine the Visual Basic integrated development environment (IDE), which is the programming environment used to develop Word VBA applications.

The second part of the book consists of Chapters Chapter 5 through Chapter 8, which provide an introduction to the VBA language, the language component common to Microsoft Visual Basic and to many of Microsoft’s major applications, including Word, Excel, PowerPoint, and Project, as well as to software from some other publishers. Individual chapters survey VBA’s data types, constants, and variables (Chapter 5, Variables, Data Types, and Constants), functions and subroutines (Chapter 6, Functions and Subroutines), intrinsic functions and statements (Chapter 7, Built-in Functions and Statements), and control statements (Chapter 8, Control Statements).

The last part of the book is devoted to the Word object model itself. This model determines which elements of Word (documents, paragraphs, fonts, and so on) are accessible through code and how they can be controlled programmatically. This portion of the book begins with a discussion of object models in general (Chapter 9, Object Models) and the Word object model in particular (Chapter 10, The Word Object Model). Subsequent chapters are devoted to taking a closer look at some of the main objects in the Word object model, such as the Application object, which represents the Word application itself, the Document object, which represents an individual Word document, and the Range and Selection objects, which represent contiguous blocks of text in a document. In addition, the final three chapters discuss methods to control the Word user interface programmatically through Word’s built-in dialog boxes (Chapter 19, Built-in Dialog Objects); UserForms, also called custom dialog boxes (Chapter 20, Custom Dialog Boxes); and Word’s menus and toolbars (Chapter 21, Menus and Toolbars). These three chapters can be read in any order, so if there is something in particular that you are interested in, you can skip ahead. I have included useful examples at the end of most of these chapters.

The appendixes provide a diverse collection of supplementary material. In particular, Appendix A, Programming Word from Another Application, provides a discussion of how to control Word programmatically from certain other VBA-hosted applications, including Microsoft Access, Excel, and PowerPoint. Appendix B, The Shape Object, is devoted to the Shape object, which can be used to add some interesting artwork to Word documents. Appendix C, Getting the Installed Printers, covers an important technique for determining what printers are available on a user’s system. (This is not quite as easy as you might think.) Finally, Appendix D, High-Level and Low-Level Languages, contains a brief overview of programming languages, which is designed to give you a perspective on where VBA fits into the great scheme of things.

Get Writing Word Macros, Second Edition 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.