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.
The last full version, 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.
VBA has only been slightly 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 compabitility 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:
Sub HelloWorld()
Dim strMessage As String
strMessage = "Hello World"
MsgBox strMessage
Debug.Print "I just made a message box that says """ & strMessage & """!"
End Sub
Questions tagged 'vba' should either contain VBA code or ask how to use specific VBA code.
Frequently Asked Questions
- Difference between Visual Basic and VBA
- How do I force VBA/Access to require variables to be defined
- How can I send an HTTP Post request to a server from Excel using VBA?
- Build SQL strings in Access/VBA
- Differences between VBA 6 and VBA 7
Beginner Resources
Additional Reading
- VBA Developer's Handbook, 2nd Edition, by Getz & Gilbert
- Professional Excel Development, 2nd Edition
General VBA Information and History