Constructing A VBA Wizard

Intended Audience

This document is for programmers who are interested in learning Visual Basic for Applications (VBA). It assumes the reader is not a Visual Basic expert, but has some programming knowledge and some experience with graphical programming concepts such as events, controls, and dialogs. To help the reader become an effective VBA programmer as quickly as possible it includes interesting techniques and lots of code examples. Reading it should help the new VBA programmer save much time, and help in exploring more of the language. If this document seems too advanced, first read some of the books suggested at the end in the "Further Reading" section. A copy of Excel version 5.0 or later is required to follow the examples in this document.

Example 1. Changing Excel's title bar

VBA represents a major advance in macro language technology. It makes macro programming easier to learn because it is based on the Basic language standard. Because it is becoming common across all Microsoft applications, there is no need to be an expert in several different languages to use the features of more than one Microsoft application in a macro project. Finally, VBA represents a fundamental change in the way Microsoft designs its products. VBA makes just about every feature in Excel programmable, and open to customization. Try the following in Excel. Right click on a worksheet tab, then choose the Insert... option. In the next dialog, select "Module" from the list. A new VBA module sheet will appear in the workbook.

Next, type in the code shown in Example 1 below. Now run it by placing the cursor on the Sub NewTitle() line and clicking the Run button (the one with the green arrow on the VBA toolbar.) If the VBA toolbar isn't visible, right click on any toolbar or select the View/Toolbars menu and choose "Visual Basic". After the code runs Excel's title bar changes from "Microsoft Excel" to whatever text was assigned to the Application.Caption property. This brief exercise illustrates that Excel's internal properties are now exposed as objects for the programmer to control.