Microsoft Office 2000/Visual Basic Programmer's Guide |
The Microsoft Office 2000/Visual Basic Programmer's Guide is divided into four parts encompassing eighteen chapters. Although it is not necessary to read the book front to back, information presented in later chapters builds on material in previous chapters. Feel free to skip to specific chapters, but note that this preface and Chapter 1, "Understanding Office Solution Development," provide a foundation for later chapters.
The following section outlines each of the chapters.
The chapters in this section present an overall view of designing your custom solution, deciding which Office technologies best suit the needs of your solution, and planning for the distribution of your solution once you are ready to put it in the hands of your users.
This chapter gives an overview of using Office 2000 technologies to develop custom solutions. The discussion provides a roadmap for understanding different aspects of solution development and how these concepts come together in the material presented in this book. When you are finished with this chapter, you'll have a better understanding of how to approach custom solution development and how to use this book to find the information you need.
Regardless of how simple or complicated your solution is, the development process always begins with fundamental design considerations and ends with choices about how to deliver your solution to users. These can be some of the most important choices you make while developing your custom solution, and this chapter explains what you need to consider in order to design your solution efficiently and effectively.
The chapters in this section form the heart of the book, providing detailed information about creating custom Office solutions.
This chapter focuses on fundamental coding guidelines, techniques, and suggestions you can employ in your code. Once these fundamentals become second nature to you, you'll discover that your code is easier to understand, debug, modify, and share with other developers. The techniques discussed in this chapter apply whether you are writing VBA code in a VBA project or script behind an HTML page or Active Server page (ASP).
All Office applications that support VBA and VBScript can use Automation (formerly OLE Automation) code to work with the objects exposed by other Office applications, as well as many other applications and services that expose object models. The key to understanding Automation is to understand objects and object models: what they are, how they work, and how they work together. This chapter and Chapter 5, "Working with Office Applications," provide a solid foundation on which to build your understanding of Office solution development.
Most Office developers are familiar with at least one Office application. This chapter teaches you how to build on what you know about one Office application in order to master the other Office applications. There are literally hundreds of exposed objects you can work with programmatically, and this chapter leads you through the object models of the Office suite to teach you what you need to build solutions with any of the Office applications.
Microsoft Office includes a set of shared components available in all Office applications. You can use these shared components to search for files, control the Office Assistant, manipulate command bars, read and write document properties, read and write script, and hook add-ins to your Office solution. Because these components are shared among all Office applications, it is easy to write code that uses these components and that will run without modification from within any Office application or custom Office solution.
As you develop applications, you'll find yourself repeatedly performing a number of operations — parsing a file path, for example, or returning all the files in a directory. Rather than rewriting these routines every time you need them, you can begin building an arsenal of procedures that solve common problems. This chapter gives you a head start by providing functions that perform some often-needed operations on strings, numbers, dates and times, files, and arrays. It also explains the key aspects of each procedure and covers fundamental VBA programming issues so that you can continue to expand your code arsenal yourself.
All code contains errors of one kind or another. How you deal with errors may be the most important part of a well-designed application. There are two categories of errors: those you can prevent, known as development errors, and those you can't prevent but can trap, known as run-time errors. You eliminate development errors by "debugging" your code. There are a wide variety of tools included in the Visual Basic Editor and the Microsoft Script Editor that can help you debug VBA code and script. You handle run-time errors by writing error handlers and by writing procedures that can validate program or environmental conditions as appropriate.
Once you understand how to work with the objects exposed by the Office applications and components, you are ready to dive into creating your own reusable objects and organizing those objects into custom object models. Building on the concepts of code maintainability and reusability introduced in earlier chapters, this discussion provides a clear understanding of this powerful technology.
Understanding how to work directly with the Microsoft Windows application programming interface (API) is an essential skill for any advanced Office developer. Although you can build sophisticated solutions without using the Windows API, knowing how and when to take advantage of this resource can extend the power and flexibility of your code. This chapter covers the basics of using functions in dynamic-link libraries (DLLs) and presents solutions to common problems by using the Windows API.
Creating a custom Office solution consists of enhancing and extending powerful applications that you and your users already have on your desktops. An add-in extends an application by adding functionality that isn't in the core product itself. This chapter explains how to create Component Object Model (COM) add-ins, which are based on a new technology available to Office 2000 that allows you to build add-ins that work in one or more of the Office applications. This chapter also discusses how to create application-specific add-ins, templates, and specialized forms of add-ins, such as wizards and code libraries.
Office 2000 contains more Web-related technologies than any previous version of Office. This chapter explains how you can use your existing VBA knowledge to write script in Office documents that will run when the documents are viewed in a Web browser. In addition, this chapter discusses the basics of DHTML and explains how to use cascading style sheets in your HTML documents. This chapter also discusses the new Microsoft Office Web Components, which are powerful ActiveX controls that let you transform Office documents into interactive Web pages. Finally, the chapter includes a discussion of how to programmatically work with Microsoft Office Server Extensions.
Adding Help to your Microsoft Office solution can reduce the amount of time required to train and support users of your solution. By using the tools provided with Microsoft HTML Help Workshop or your favorite HTML editor, you can author topics for a Help system by using the same tools and technologies you use to create Web pages — including hyperlinks, ActiveX controls, scripting, and DHTML support. You can then compile your topics into a single file and display them by using the same viewer that is used to display Help in Office 2000.
Most Office solutions manage data in one form or another. Whether you are using Microsoft Access to build database applications or one of the other Office applications to work with data stored in a data source, this section tells you what you need to know to access and manipulate data in a variety of situations.
Office 2000 includes ADO as a powerful new programmatic interface to data no matter where the data resides or what form the data takes. This chapter discusses what you need to know about ADO to make your Office solutions work better and faster with data in any form. If you have developed custom solutions in earlier versions of Office, you are already familiar with DAO. Through side-by-side comparisons of comparable data access techniques and strategies, this chapter teaches ADO by building on what you already know about DAO.
Once you have mastered the techniques for retrieving data, you'll want to know how to display and manipulate that data. This chapter illustrates different ways to present and analyze data. The concepts in this chapter build on the introductory discussions begun in Chapter 1, "Understanding Office Solution Development," about choosing and using the right Office application to meet the requirements of your custom solution.
Building solutions that tap the capabilities of a multiuser database application can be difficult and intimidating. This chapter helps you understand the various types of multiuser database applications and determine which type is best suited to your Office solution.
Security issues take on increasing significance as computer networks expand to include the World-Wide Web. In addition, as a developer, you need to know how to protect your investment in the intellectual property that is your custom solution. The chapters in this section discuss what you need to know about securing your custom Office solution, protecting your code, and taking full advantage of the new security-related features of Office 2000.
If your solution contains or provides access to sensitive information, such as legal documents or payroll records, you may need to control access to this information. If you are retaining the ownership of the VBA code you develop, you also need to prevent unauthorized access to your solution's code. Furthermore, with the advent of macro viruses, you need to assure users and administrators that they can trust the macros (VBA code) contained in any Office documents that are part of your solution. This chapter discusses how to address these access security and virus security issues for Word, Excel, and PowerPoint through various means, including the use of digital signatures. It also discusses how to secure VBA code, which applies to Access and FrontPage as well.
Access provides a sophisticated security environment for controlling access to object definitions and data. This chapter discusses the Access security model and how to implement it successfully, and provides complete code samples for programmatically creating and maintaining security settings. This chapter also discusses how to password-protect a database, how to secure VBA code in an Access database by saving the database as an .mde file, and how to set up security when accessing databases through data access pages.