© 2011 Ben Van Vliet
VISUAL BASIC FOR APPLICATIONS
Visual Basic for Applications (VBA) is a programming language that runs behind Excel.
The Microsoft Developer Network (MSDN) website has a wealth of documentation—
both how to’s and references—on Excel/VBA at:
Specifically, the Excel 2007 Developer Reference link will lead you to How Do I… in
Excel 2007 and the Excel Object Model Reference which maps the Excel Object
Model. If you encounter object references in this text that you are unfamiliar with, you
should first refer to the MSDN reference for information.
Here is a brief list of built-in Excel objects you should be familiar with:
You should look at the descriptions of these objects as well as others. You will not be
able to memorize all the Excel objects, so the key is to know what kinds of objects are
available in VBA and find and learn about them quickly. As you will see, these objects
consist of three parts:
Properties, which are attributes of an object.
Methods, which are functionalities of an object.
Events, which are actions that are initiated within the scope of an object, but
handled by methods outside of an object.
Another good site for VBA code and explanation is Anthony’s VBA Page at:
As with all things Excel, the best way to learn is to jump in and start doing. To add VBA
code to your spreadsheet, open the Visual Basic Editor (VBE) environment by clicking
on Developer | Visual Basic. (If the Developer tab is not available, click on the Office
button in the upper right-hand corner, then click on Excel Options, and turn on Show
Developer tab in the Ribbon.) In the VBE, add a module. From the menu bar, click
Insert | Module. A blank code window will appear. We use the VBE create and modify
procedures—functions and sub-routines. Every Excel file can contain VBA code.
The Selection object may not appear in the MSDN reference list. But, it is an important object. The
Selection object “represents the active selection, which is a highlighted block of text or other elements in
the document that a user or a script can carry out some action on.” For more information from within
MSDN, you should search on Selection Object.
The Cells object may not appear in the MSDN reference list. This kind of problem is a common
occurrence in technology documentation. It’s all part of what makes technology so hard. For more
information from within MSDN, you should search on Cells Object.