Tag Info

Visual Basic for Applications (VBA) is an event-driven, object-oriented programming language for writing macros, used for the entire Office suite as well as other applications. If your question is specifically about programming Excel, Access, Word or Outlook, also use the appropriate tag: excel-vba, access-vba, word-vba or outlook-vba.

Visual Basic for Applications (VBA) is an event-driven programming language which was first introduced by Microsoft in 1993 to give Excel 5.0 a more robust object-oriented language for writing macros and automating the use of Excel. The language and its runtime quickly matured and began being used in products beyond Microsoft Office applications.

VBA 6, was shipped in 1998 and includes a myriad of licensed hosts, among them: Office 2000 - 2010, AutoCAD, PI Processbook, and the stand-alone Visual Basic 6.0. VBA 6 code will run equally well on any host, though the underlying objects native to each host will vary. Though still built into Microsoft Office applications, VBA ceased to be an integral of part of Microsoft's development platform when Visual Basic .NET shipped with the first version of the .NET framework in 2002. Additionally, in some Starter editions of Office applications, the VBA Editor (VBE) is not available, and programming in VBA cannot be done.

VBA has been rarely updated since, only including new features to allow it to remain compatible with x64 versions of Windows and Office. VBA 7 was released in 2010 to address the new 64-bit version of Microsoft Office, which shipped in 2010. There are several important changes made to VBA 7 that make it different from VBA 6, namely compatibility with both 32 and 64-bit versions of Office. Applications using VBA 7 must address both backwards compatibility and 64-bit-safe issues.

It was removed from Office for Mac 2008, however Microsoft returned VBA to Office 2011. Microsoft has continually been questioned about whether or not VBA will be removed altogether from Office and has repeatedly replied "no".

VBA inherits much of its syntax from the BASIC programming language, where language features tend to be explicitly expressed in words (e.g. If ... Then ... End If, Function ... End Function). It also has many object-oriented features (such as classes and interfaces) and even has some dynamic features (Variant). Below is a simple subroutine, which generates a message box and prints a message to the Immediate window:

It is expected that questions tagged vba should either contain VBA code or ask how to use specific VBA code. Also, while code written in VBA is typically called a 'macro', the macros tag should not be used for general VBA questions. Please see the macros wiki entry page for more information about correct usage.

If your code is specific to an Office application (Excel, Word, Outlook, etc.) then tag it with one of the application-specific tags found below, in addition to this one.