VBA's focus is on programming the
Office suite. It allows to automate almost all interaction between a user and an office document that otherwise would have to be carried out with mouse or keyboard.
VBA Environment
A VBA program runs in a
VBA Environment which is hosted and controlled by another program, typically
MS Office programs (
Word,
Excel …).
An environment consists of one ore more VBA Projects.
The amount of trust that is granted to an
Office VBA environment is controlled in the respective
Trust Center.
VBA Project
A VBA Project is a container for VBA code. Thus, all VBA programs run in the context of a VBA Project.
A project has a
project name and consists of a set of named
modules and of an ordered list of
project references.
A project reference refers to a another project. It allows a project to access public entities in that other project.
Three types of projects:
- Source (written in the VBA language)
- Library (not necessarily written with the VBA language)
- Host: a library project that is inserted into the VBA Environment by the host application. An example of a host project is the VBA project (which contains the standard library).
The special project
VBA is available in every VBA Environment. The VBA project contains a set of
classes,
functions, enums and constants: the so called
VBA standard library.
The components within a VBA project can be accessed via the
VBE object
VBProject
. The functionality of an entire project can be added to another VBA project using the other's project
reference
object.
In Excel, the property
workbook.hasVBProject
is
true
if the workbook has a VBA project.
Apparently, a VBA project can be digitally signed, see the
workbook.vBASigned
property.
The VBA project
A (host) project named VBA is present in every VBA Environment.
This project contains VBA's standard library.
Among others, this
VBA project contains a rather mysterious
global
object.