O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required


As the title suggests, this book is intended for those who want to learn how to program Microsoft Word 97 or later.

I guess that I cannot avoid the question, “Why would anyone want to program Microsoft Word?” The answer is simple: to get more power out of this formidable application. As you will see, there are many things that you can do at the programming level that you cannot do at the user-interface level, that is, with the menus and dialog boxes of Word. Chapter 1, Introduction, provides some concrete examples of this.

This book provides an introduction to programming the Word object model using Visual Basic for Applications (VBA). However, it is not intended to be an encyclopedia of Word programming. The goal here is to acquaint you with the main points of Word programming—enough so that you can continue your education (as we all do) on your own. The point is that after reading this book, you should not need to rely on any other source except the Word VBA help file or a good Word VBA reference book (such as O’Reilly’s forthcoming Programming the Word Object Model by Julianne Sharer and Arthur Einhorn) and a nice object browser (such as the Enhanced Object Browser, a coupon for which is included in the back of this book).

It has been my experience that introductory programming books (and, sadly, most trade computer books) tend to do a great deal of handholding (to put the matter euphemistically). They cover concepts at a very slow pace, primarily by padding them heavily with overblown examples and irrelevant anecdotes that only the author could conceivably find amusing, especially the second or third time that we are forced to read them while looking for a few facts. Frankly, I find such unprofessionalism incredibly infuriating. In my opinion, it does the reader a great disservice to take perhaps 400 pages of information and pad it with another 600 pages of irrelevant junk.

There is no doubt in my mind that we need much more professionalism from our authors, but it is not easy to find writers who have both the knowledge to write about a subject and the training (or talent) to do so in a pedagogical manner. (I should hasten to add that there are a number of excellent authors in this area; it’s just that there are not nearly enough of them.) Moreover, publishers tend to encourage the creation of 1000-plus-page tomes because of the general feeling among the publishers that a book must be physically wide enough to stand out on the bookshelf! I shudder to think that this might, in fact, be true. (I am happy to say that O’Reilly does not seem to have succumbed to this opinion.)

On the other hand, Writing Word Macros is not a book in which you will find much handholding. (Nor will you find much handholding in any of my books.) The book proceeds at a relatively rapid pace from a general introduction to programming, through an examination of the Visual Basic for Applications programming language to an overview of the Word object model. Given the enormity of the subject, not everything is covered, nor should it be. Nevertheless, the essentials of both the VBA language and the Word object model are covered, so when you have finished the book, you will know enough about Word VBA to begin creating effective working programs.

I have tried to put my experience as a professor (about 20 years) and my experience writing books (about 30 of them) to work here to create a true learning tool. I hope that this book can be read (perhaps more than once) and also serve as a useful reference.

A Title Change and Word 2000 Compliance

After careful consideration, the folks at O’Reilly and I have decided that the original title of this book, Learning Word Programming, was probably not the best choice of title. I am convinced that many Word users can benefit from a knowledge of how to create macros using the Visual Basic editor. However, the word “Programming” in the previous title may have been a bit intimidating to some Word users.

Writing Word macros is probably not for the casual Word user, but if you are a semi-serious to serious user of Word, then this book can help you get considerably more power out of this application.

Accordingly, we have changed the title of the book to the more user-friendly Writing Word Macros. This also brings the title in line with my book, Writing Excel Macros (also published by O’Reilly).

I have also taken this opportunity to make sure that the book is up-to-date with respect to the release of Word 2000. The Word 2000 object model differs little from its predecessor. There are only a handful of new objects, mostly related to the Internet. The main change for us is the treatment of the Documents collection. This change is due to the fact that Word 2000 is now a more-or-less single document interface application; that is, each instance of Word 2000 can have only one document open at a time. (Actually, the situation is somewhat more involved and is discussed in detail in Chapter 12, The Document Object.)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required