Chapter 23. Getting Started with VBA


  • Basic VBA syntax

  • Storing data—variables, arrays, and constants

  • VBA operators

  • Conditional and loop statements

  • Writing and calling procedures

VBA, or Visual Basic for Applications, is the programming language built in to the programs in the Microsoft Office suite, including Outlook. To be able write and edit Outlook macros, you must have a decent understanding of the VBA language. Fortunately, it is a fairly easy language, having been designed from the very beginning to be accessible not just to computer geeks but also to us ordinary mortals.

This chapter provides an introduction to the VBA language, giving you an overview of the most essential language elements. It is by no means a complete treatment of VBA—that would require an entire book in itself! With the information provided in this chapter, you can start writing useful macros. As your needs and interest dictate, you can find more information on VBA in the online help, books, and other sources.

Basic VBA Syntax

A VBA program, or macro, is made up of a series of VBA statements. Each statement is an instruction that tells Outlook to perform an action such as adding two numbers or opening an email message. Each statement is on its own line in the source code, although long lines can be split with a space followed by an underscore in order to make them easier to read in the editor. Thus, the following is treated as a single line of code:

ActiveWorkbook.CustomDocumentProperties.Add _ Name:="Part ...

Get Microsoft® Outlook® 2007 Bible now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.