|
VBA for Office 2000 Unleashed
Introduction
Invention is the mother of necessity. With the release of Office 2000, Visual Basic for Applications has now been on the macro programming stage for about 5 years. That's not all that long, even in geek years, so it's more than a little remarkable that VBA has gone from programming upstart to application stalwart in that short time. After all, do you know anyone who still uses the old Excel macro language or WordBasic? Probably not, and for good reason. Trying to pull together even a modest program using those clunker languages was a nasty, brutish, and long process. On the other hand, VBA, with its superb programming environment and easy-to-learn syntax, can handle even the most ambitious application programming chores. That's not to say, however, that VBA is only good for major projects. As a writer, I use Word constantly, and over the years I've developed dozens of small macros, functions, and forms that streamline or automate repetitive chores. Most of these routines consist of only a few lines of code, and each one saves me only about 30 seconds to a minute, depending on the task. But I use these routines 50 or 100 times a day, so I end up saving myself anywhere from 30 to 90 minutes a day! That's pretty remarkable, but the proof is in the pudding: I can now write far more pages in a day than I used to. (Don't tell my editor!)
Whether your concern is ease-of-use or personal productivity, there's little doubt VBA is the Office programming language of choice. So now all you have to do is learn how to use it, and that's where this book comes in. I take you through all the basic programming constructs, including variables, loops, and the other tools that are part of every coder's arsenal. I also run through every feature found in the VBA Editor and discuss the all-important topic of objects, particularly those objects that form the heart of Word, Excel, PowerPoint, and Access. So even if you've never programmed before, this book will have you slinging code in no time flat. Experienced programmers will appreciate the book's intermediate-to-advanced sections that cover user interfaces, database programming, Internet programming, debugging, and much more.
The version of VBA that ships with Office 2000 is 6.0. This new version isn't radically different from the VBA 5.0 that was featured in Office 97. However, there are hundreds of changes, large and small, so there should be something for everyone. Here's a summary of a few of the major changes that VBA 6.0 brings to the programming table:
What You Should Know Before Reading This BookMy goal in writing this book was to give you complete coverage of the VBA language, as well as numerous examples for putting the language to good use. Note, however, that this book isn't a programming tutorial per se. So although I cover the entire VBA language, many relatively low-level topics are presented quickly so that I can get to meatier topics. Therefore, although you don't need programming experience to read this book, knowledge of some programming basics would be helpful. I've tried to keep the chapters focused on the topic at hand and unburdened with long-winded theoretical discussions. For the most part, each chapter gets right down to brass tacks without much fuss and bother. To keep the chapters uncluttered, I've made a few assumptions about what you know and don't know:
How This Book Is Organized
To help you find the information you need, this book is divided into eight parts that group related tasks. The next few sections offer a summary of each part.
The five chapters in Part I provide coverage of the fundamentals of VBA programming. Chapter 1 familiarizes you with the layout of the VBA Editor, and subsequent chapters teach you about variables, operators, expressions, objects, and procedure control.
Part II takes an in-depth look at programming all the major Office 97 applications. I'll discuss the objects, properties, methods, and events that are unique to Word, Excel, PowerPoint, and Access.
The look and feel of your VBA applications is the subject of the three chapters in Part III. I'll begin with some basic methods for interacting with the user, and then I'll show you how to build forms and control them programmatically, how to assign your procedures to menus and toolbars, and how to use VBA to build menus and toolbars via code.
These days, it's a rare VBA application that operates in splendid isolation. Most applications will require at least a little interaction with software other than the underlying VBA program. Integrating multiple applications is the topic of the four chapters in Part IV. You'll learn how to control other programs directly, how to use Dynamic Data Exchange, how to program OLE and ActiveX objects, how to control programs via Automation, and how to work with class modules.
Working with information stored in databases and tables is a crucial topic in this era of client/server setups and intranet-based organizations. From simple Excel list maintenance chores, I'll progress to programming the powerful Data Access Objects model, working with ODBC, dealing with database security, ActiveX Data Objects, and lots more.
Part VI shows you how to program VBA's Internet- and intranet-related features. Topics include publishing to HTML, programming hyperlinks, building a custom Web browser, programming Web pages with VBScript, and controlling Outlook's email feature via VBA.
This part of the book presents a hodgepodge of advanced VBA techniques. You'll learn how to trap errors, how to debug your code, how to use the Windows API, how to work with low-level file I/O and compiler directives, read and write Registry data, and digitally sign your VBA projects.
Fine words butter no parsnips, as they say, so I've crammed this book full of useful, real-world examples. Most of these examples highlight a specific feature, so they tend to be short. Here in Part VIII, however, I offer up some longer examples that show you how to put together full-fledged VBA applications.
I've also tacked on a few extra goodies at the end of this book. The appendixes include a complete listing of VBA's statements and functions (Appendixes A and B), Windows 98's VBScript-driven Windows Scripting Host (Appendix C), the Windows ANSI character set (Appendix D), and an HTML primer (Appendix E).
Visual Basic for Applications for Office 2000 Unleashed is designed to give you the information you need without making you wade through ponderous explanations and interminable technical background. To make your life easier, this book includes various features and conventions that help you get the most out of the book and VBA itself.
The Acknowledgments DepartmentRobert Pirsig, in Zen and the Art of Motorcycle Maintenance, wrote that "a person who sees Quality and feels it as he works, is a person who cares." If this book is a quality product (and I immodestly think that it is), it's because the people at Sams editorial cared enough to make it so.
So a round of hearty thanks is in order for all the good people who worked on this project. You'll find them all listed near the front of the book, but I'd like to extend special kudos to the folks I worked with directly: Acquisitions Editor Sharon Cox, Development Editor Tony Amico, Production Editor Dawn Pearson, Copyeditor Linda Morris, Tech Editor Lowell Mauer, and Software Specialist Michael Hunter. I'd also like to thank Bruce Clingaman for his valued input and, last but proverbially not least, all the thousands of readers from the first edition of the book who wrote to me with praise and suggestions.
Paul McFedries is a freelance writer with more than 25 years of programming experience. McFedries is the author of more than two dozen computer books that have sold nearly 2 million copies worldwide. His titles include the Sams books Windows 98 Unleashed and Paul McFedries' Windows 98 Unleashed Professional Reference Edition, as well as the Que books The Complete Idiot's Guide to Windows 98 and The Complete Idiot's Guide to Creating an HTML 4 Web Page. Back to the VBA for Office 2000 Unleashed home page
Copyright © 1995-2008 Paul McFedries and Logophilia Limited |