Microsoft Office 97/Visual Basic Programmer's Guide |
Introduction |
|
Use the following suggestions to get the most from the time you spend learning Visual Basic for Applications (referred to as "Visual Basic" for the remainder of this book).
Learn Microsoft Office first The more you know about Office, the better prepared you'll be to venture into Visual Basic. Most Visual Basic procedures perform a sequence of actions in Office, and most instructions in a procedure are equivalent to Office commands or actions. Consequently, working with Visual Basic is a little like working with Office without a user interface; instead of choosing commands and selecting options in dialog boxes, you write Visual Basic instructions. The statements and functions you use to write instructions are much easier to understand if you're already familiar with the features they represent in Office.
Also, if you know Office well, you can better answer the question you're most likely to ask yourself when writing a macro: "What's the best way to do this?" People have been known to write long macros for tasks that could have been handled by a single Office command.
Learn what you need, when you need it Learn what you need for the task at hand. Visual Basic can seem overwhelming at first, particularly if you don't have any experience with programming languages. A great way to begin learning Visual Basic is to investigate how to accomplish a particular task programmatically. As you gain experience writing procedures that automate different types of tasks, you'll cover a lot of ground.
Use the macro recorder The macro recorder a feature that's available with Microsoft Excel, Word, and PowerPoint can record the corresponding Visual Basic instruction for virtually every action you take in Office. You can use the macro recorder to see how actions performed in Office translate into Visual Basic instructions, and vice versa. Also, you'll find that recording part of a macro is often faster and easier than writing out the instructions.
Use Visual Basic Help Help is a powerful tool for learning Visual Basic. In a Visual Basic module, you can type a keyword and, with the insertion point positioned somewhere in the keyword, press F1 to immediately display the Visual Basic Help topic for that keyword. Most Visual Basic Help topics for keywords include examples you can copy and paste into your macros. For more information, see the following section, "Using Online Help."
|
Microsoft Office provides an extensive Help system for the Visual Basic language, the objects that Office supports, and the properties and methods of those objects.
If you clicked Typical when you installed Office, you'll need to run Setup again to install Help for Visual Basic for the applications you want to program in.
After you've displayed a Help topic, you can click the Help Topics button in the Help window to display the Help Topics dialog box, which contains three tabs: Contents, Index, and Find. You can then either look up a specific topic or Visual Basic term on the Contents or Index tab or perform a fulltext search from the Find tab.
Note In
the Visual Basic Editor, clicking Contents and Index on the Help
menu displays the contents and index of Help for the Visual Basic
Editor itself. From the Contents tab in Visual Basic Editor Help,
you can display the contents and index of Visual Basic Help for
Microsoft Excel, Word, or PowerPoint by double-clicking the book
title that includes the name of the application you're working
in (for example, "Microsoft Word Visual Basic Reference"),
and then double-clicking the shortcut in that book (for example,
"Shortcut to Microsoft Word Visual Basic Reference").
The Help Topics dialog box should reappear, displaying the contents
and index for Visual Basic Help for your application.
|
Following are descriptions of the various resources you can use to get additional information about programming with Visual Basic in Office.
Technical Support Services
Microsoft offers a variety of support options to help you get
the most from your Microsoft product. For more information about
available support services, see Getting Results with
Microsoft Office 97.
For basic technical support outside the United States, contact
the Microsoft subsidiary office that serves your area. Microsoft
subsidiary offices and the countries they serve are listed in
Getting Results with Microsoft Office 97.
Microsoft Office Developer Forum
You can get the latest information about developing custom applications
for Office at the Microsoft Office Developer Forum Web site at http://www.microsoft.com/officedev/
Microsoft Press Books
In addition to the Microsoft Office 97/Visual Basic
Programmer's Guide, Microsoft Press®
offers a number of books to help you get started programming in
Visual Basic. These books help you learn how to automate Office
tasks and create custom applications as easily and as quickly
as possible. The easytofollow lessons include clear
objectives and realworld business examples so that you can
learn exactly what you need to know, at your own speed.
For a technical exploration of the wide range of line-of-business
development opportunities available to Office 97 developers,
see the Microsoft Office 97 Developer's Handbook,
ISBN 1-57231-440-0, by Christine Solomon.
Building Microsoft Outlook 97 Applications,
ISBN 1-57231-5736-9, by Peter Krebs is a results-oriented book
that offers both the nonprogrammer and the experienced IS professional
the information, strategies, and sample applications they need
to get started building useful groupware and mail-enabled applications.
For information about other Microsoft Press titles, see the Microsoft
Press Web site at http://www.microsoft.com/mspress/
Mastering Office 97 Development
Mastering Office 97 Development is a CD-ROM product available
from Microsoft. Use this self-paced training tool to develop real-world
skills that you can put to work right away. Become proficient
with Visual Basic for Applications, Office 97 object modules,
and more. More than 40 hours of labs, demos, sample code, and
articles plus valuable tips and techniques
get you up to speed fast. Use the powerful Boolean search engine
and comprehensive index to find just information you need when
you need it. Narrated demonstrations and interactive lab exercises
walk you through complex concepts and help you design your own
Office 97-based applications.
|
The chapters in this book cover basic concepts pertaining to object models and Visual Basic programming, the object models for the Office applications, and major feature areas of Visual Basic.
Chapter 1, "Programming Basics," provides a brief overview of the mechanics of writing Visual Basic code.
Chapter 2, "Understanding Object Models," is an introduction to the concept of programmable object models.
Chapter 3, "Microsoft Access Objects," discusses the Microsoft Access object model in detail.
Chapter 4, "Microsoft Excel Objects," discusses the Microsoft Excel object model in detail.
Chapter 5, "Microsoft Outlook Objects," discusses the Microsoft Outlook object model in detail.
Chapter 6, "Microsoft PowerPoint Objects," discusses the Microsoft PowerPoint object model in detail.
Chapter 7, "Microsoft Word Objects," discusses the Microsoft Word object model in detail.
Chapter 8, "Menus and Toolbars," and Chapter 12, "ActiveX Controls and Dialog Boxes," show you how to add interactive, custom userinterface elements to your Visual Basic applications.
Chapter 9, "Microsoft Office Assistant" discusses the Office Assistant object model in detail.
Chapter 10, "Shapes and the Drawing Layer," discusses the Office Art object model in detail.
Chapter 11, "Data Access Objects," explains how to use Data Access Objects (DAO) to import and export information stored in a database.
Chapter 13, "Optimizing for Size and Speed," provides several easy techniques that can make your Visual Basic code faster and more concise.
Chapter 14, "Debugging and Error Handling," shows you how to find and eliminate bugs in your code before you run it and how to handle errors that occur while your code is running.
Chapter 15, "Developing Applications for the Internet and World Wide Web," provides information about how to control the new Internetready features in Office applications programmatically.
The appendixes provide helpful information for experienced users of XLM or WordBasic who are switching to Visual Basic.
|
This book uses the typographic conventions listed in the following table. You might not recognize all the terms or Visual Basic keywords yet, but you'll learn more about them later.
Example of convention | Description |
setup | Words or characters you're instructed to type are formatted as bold. |
Sub, If, ChDir, MsgBox, True, Add, Height, Application, Range, Row | Bold words with the initial-letter capitalization indicate either a language-specific term (a property, method, event, or object name), another Visual Basic keyword, or an interface element (such as a menu command or a toolbar button). |
object | In text, italic type indicates important new terms, usually the first time they occur in the book. |
PropertyName | In code syntax, italic type indicates placeholders for information you're to supply. |
ENTER | Small capital letters are used for the names of keys and key combinations, such as ENTER and CTRL+R. |
CTRL+V | A plus sign (+) between key names indicates a key combination, or shortcut keys. For example, CTRL+V means to hold down the CTRL key while pressing the V key. |
DOWN ARROW | Individual arrow keys are referred to by the direction of the arrow on the key (LEFT, RIGHT, UP, or DOWN). The phrase "arrow keys" is used to describe these keys collectively. |
BACKSPACE, HOME | Other navigational keys are referred to by their specific names. |
myVar | This font is used for example code. |
Sub StockSale ( )
. . . End Sub | A column of three periods indicates that part of an example has been intentionally omitted. |
|