Writing macros using VBA, an introduction

On this page you will find information to get you started with VBA (Visual Basic for Applications). It is assumed you have some basic experience in programming. This page uses the many resources:

A few screencasts to get you started

The screencasts were done in Excel, but are applicable to other Office applications also.

Writing procedures in VBA

A procedure is a named series of program statements that can be started independently.

Declaring variables and constants

Variables are used to manage the data in computer memory. Most variables you declare represent the data you are processing, the programs input or output. In addition you will use internediary variables to control the current state of the process for eample is as part of the program you asked if he wants to save data, the reply will be stored in a variable which will then determine what will happen next, depending.

It is good to declare and use constants

Controlling Program Flow

Read for an introduction on controlling program flow

Loop to repeat actions

Looping allows you to run a group of statements repeatedly. In VBA there are three types loops:

Conditional processing using If or Select

Calling procedures

Interacting with the user

The easiest way to communicate with a user is using built-in dialogs:

Working with classes and objects

Automating one application from another

A common requirement is to create documents (Word, PDF, ...) and email using data stored in MS Access or Excel. Such a working together of several application is called Office automation.

Using the VB Editor

Debugging your code