Visual Basic For Applications
Visual Basic For Applications
Visual Basic for Applications (VBA) is an implementa- compatible with Visual Basic .NET (VB.NET). VBA is
tion of Microsoft's event-driven programming language, proprietary to Microsoft and, apart from the COM interVisual Basic 6, and its associated integrated development face, is not an open standard.
environment (IDE).
Visual Basic for Applications enables building userdened functions (UDFs), automating processes and accessing Windows API and other low-level functionality
through dynamic-link libraries (DLLs). It supersedes
and expands on the abilities of earlier application-specic 2 Automation
macro programming languages such as Words WordBasic. It can be used to control many aspects of the host apInteraction with the host application uses OLE Automaplication, including manipulating user interface features,
tion. Typically, the host application provides a type lisuch as menus and toolbars, and working with custom
brary and application programming interface (API) docuser forms or dialog boxes.
umentation which document how VBA programs can inAs its name suggests, VBA is closely related to Visual Ba- teract with the application. This documentation can be
sic and uses the Visual Basic Runtime Library, but it can examined from inside the VBA development environnormally only run code within a host application rather ment using its Object Browser.
than as a standalone program. It can, however, be used to
Visual Basic for Applications programs which are written
control one application from another via OLE Automato use the OLE Automation interface of one application
tion. For example, it is used to automatically create a
cannot be used to automate a dierent application, even
Word report from Excel data, which are automatically
if that application hosts the Visual Basic runtime, because
collected by Excel from polled observation sensors. VBA
the OLE Automation interfaces will be dierent. For exhas the ability to use (but not create) (ActiveX/COM)
ample, a VBA program written to automate Microsoft
DLLs, and later versions add support for class modules.
Word cannot be used with a dierent word processor,
VBA is built into most Microsoft Oce applications, in- even if that word processor hosts VBA.
cluding Oce for Mac OS X (apart from version 2008)
Conversely, multiple applications can be automated from
and other Microsoft applications such as Microsoft Mapthe one host by creating Application objects within the
Point and Microsoft Visio, as well as being at least parVBA code. References to the dierent libraries must be
tially implemented in other applications such as ArcGIS,
created within the VBA client before any of the methAutoCAD, CATIA, Corel Draw and WordPerfect.
ods, objects, etc. become available to use in the application. This is achieved through what is referred to as
Early or Late Binding. These application objects create
the OLE link to the application when they are rst cre1 Design
ated. Commands to the dierent applications must be
done explicitly through these application objects in order
Code written in VBA is compiled[1] to a proprietary to work correctly.
intermediate language called P-code (packed code),
which the hosting applications (Access, Excel, Word, VBA code written in Microsoft Access can establish refOutlook, and PowerPoint) store as a separate stream in erences to the Excel, Word and Outlook libraries; this will
COM Structured Storage les (e.g., .docx or .xlsx) in- allow creating an application that runs a query in Access,
dependent of the document streams. The intermediate exports the results to Excel, formats the text, then writes
code is then executed[1] by a virtual machine (hosted by a mail merge document in Word that it automatically ethe hosting application). Despite its resemblance to many mails to each member of the original query through Outold BASIC dialects (particularly Microsoft BASIC, from look.
which it is indirectly derived), VBA is incompatible with VBA programs can be attached to a menu button, a
any of them except Visual Basic, where source-code of macro, a keyboard shortcut, or an OLE/COM event, such
VBA modules and classes can be directly imported, and as the opening of a document in the application. The lanwhich shares the same library and virtual machine. Com- guage provides a user interface in the form of UserForms,
patibility ends with Visual Basic version 6; VBA is in- which can host ActiveX controls for added functionality.
1
Security concerns
REFERENCES
Development
As of July 1, 2007, Microsoft no longer oers VBA distribution licenses to new customers. Microsoft intended
to add .NET-based languages to the current version of
VBA ever since the release of the .NET Framework,[2]
of which versions 1.0 and 1.1 included a scripting runtime technology named Script for the .NET Framework.[3]
Visual Studio .NET 2002 and 2003 SDK contained a
separate scripting IDE called Visual Studio for Applications (VSA) that supported VB.NET.[4][5][6] One of its
signicant features was that the interfaces to the technology were available via Active Scripting (VBScript and
JScript), allowing even .NET-unaware applications to be
scripted via .NET languages. However, VSA was deprecated in version 2.0 of the .NET Framework,[6] leaving no clear upgrade path for applications desiring Active Scripting support (although scripts can be created
in C#, VBScript, and other .NET languages, which can be
compiled and executed at run-time via libraries installed
as part of the standard .NET runtime).
5 See also
Visual Studio Tools for Oce
Microsoft Visual Studio
Microsoft FrontPage
OpenOce Basic
6 References
[1] ACC: Visual/Access Basic Is Both a Compiler and an Interpreter
[2] Visual Studio for Applications
[3] Introducing Visual Studio for Applications
[4] Script happens .NET: MSDN
[5] Microsoft Takes Wraps O VSA Development Technology
Support for VBA in the Mac OS X version of Microsoft [6] VSA scripting in .NET
Oce was dropped (for one version) with the release
of Microsoft Oce 2008 for Mac.[7][8] The ocial rea- [7] WWDC: Microsoft updates Universal status of Mac
apps. Macworld. 2006-08-07. Retrieved 2007-05-25.
son given was that VBA relied heavily on machine code
written for the PowerPC architecture, and that rewrit- [8] Oce 2008 without VBA
ing this code for dual PowerPC/Intel architectures would
have added another two years to the development of the [9] The Reports of VBAs Demise Have Been Greatly Exaggerated
suite. However, the Oce suite can be automated via
AppleScript to an extent. VBA was restored in Microsoft [10] Clarication on VBA Support
Oce for Mac 2011. Microsoft has clearly stated that
they have no plans to remove VBA from the Windows [11] Compatibility Between the 32-bit and 64-bit Versions of
Oce 2010
version of Oce.[9][10]
With Oce 2010, Microsoft has introduced VBA7 which
now contains a true pointer data type: LongPtr. This
new data type allows referencing 64-bit address space.
The 64-bit install of Oce 2010 does not support common controls of MSComCtl (TabStrip, Toolbar, StatusBar, ProgressBar, TreeView, ListViews, ImageList,
Slider, ImageComboBox) or MSComCt2 (Animation,
UpDown, MonthView, DateTimePicker, FlatScrollBar)
7.1
Text
7.2
Images
7.3
Content license