What Is VBA

extensible, and it's ActiveX (or OLE automation) that provides the interface between VBA and its host application. It's this support for OLE automation that makes VBA an outstanding tool for rapidly developing robust Windows applications.

Until the launch of VBA 5.0 in early 1997, the language had no development environment; very much like VBScript today, VBA was simply a language interpreter. VBA 5.0 marked the start of an exciting new chapter for VBA; it now has its own integrated development and debugging environment running within the process space of the host application.

VBA itself becomes more object-oriented with each release, but the latest release (Version 6.0) adds relatively few functions and keywords to the VBA language. Instead, extra functionality has been incorporated into VB6 using new object models, and again it's the VBA language that allows you to integrate these object models into your application.

How Does VBA Differ from VB?

VBA is a programming language common to Microsoft Visual Basic, Microsoft Office, Microsoft Project, Visio, and a whole host of other applications. Although the particular "flavor" of VBA you use depends on the environment that hosts VBA, the core VBA language is basically identical regardless of the environment that hosts it. In other words, VB, the Microsoft Office suite, and a number of other applications share a common programming language named VBA that is identical across its various hosts.

Having made this generalization, we should introduce two qualifications. First, there are some differences that depend on the time at which the product hosting VBA was released. For example, although VB5 and Office 97 both indicate that they include version 5.00 of the VBA language, VBA for VB5 supports a number of language elements (like the addressof operator) that are not supported by VBA for Office 97. This is because VB5 was released somewhat after Office 97, which left more time to incorporate some new features in the former implementation that were omitted from the latter.

Second, there are some major differences that focus more on usage than on language elements. This is because VB is a complete RAD environment that features a range of user interface components and relies on VBA as its programming language:

• VBA programs and the VBA development environment itself both execute in the same process space as the host application, whereas VB programs can be compiled into executables and run in their own process space, independent of the host (i.e., Visual Basic) environment.

• Related to this, VB applications can be compiled into native code executables, whereas VBA applications are always interpreted.

• VB applications can be complied into ActiveX components and used within other applications.

• Unlike the retail version of VB, VBA allows code to be written for multiple platforms. Versions of VBA are currently available for Windows 95 and Win-

4 Chapter 1 - Introduction dows NT on Intel; for NT on MIPS, Power PC, and Alpha RISC; and for Macintosh/Power PC.

• VBA as a hosted programming language and VBA in VB are typically used differently in developing applications. With VB, you normally use VBA to write code that references controls, procedures, and functions that are part of the program itself. With VBA, the vast amount of code is related to referencing the methods, properties, and functions that make up the object model of the host application. This is the overriding difference between VB and VBA, although the two are beginning to converge in this area as VBA is increasingly used in VB to control the ever-expanding list of VB's own object models, VB class modules, and in-process and out-of-process servers.

• The programs created by the two products are typically used for different purposes. VB creates standalone applications. VBA, though it can be used to create "applications" that act as intermediaries between the user and the host application (like Word or Excel) typically provides some essential service or adds some enhancement to its host application.

How Does VBA Differ from VBScript?

VBScript was born of VBA.* VBA supports OLE automation; that is, you can create instances of objects, call their methods, and set and return object properties. This functionality was left out of VBScript, since it was thought too risky for the web scripting environment. However, when used at the server side with Active Server Pages, VBScript has almost the same OLE (ActiveX) functionality as VBA.t In addition, VBScript is simply an interpreted language component; it has no design environment apart from the ActiveX Control Pad. In contrast, from Version 5 onward, VBA has its own integrated development environment, including an integrated debugging window, a Properties window, and many of the standard features that were originally found in the VB IDE.

How Does a VBA Program Differ from a Macro?

VBA takes over where macro languages left off. Macro languages are used to simply automate repetitive tasks in an application. Because VBA replaced the macro languages found in Office applications, there is still a common misconception that VBA is a macro language. However, referring to VBA as a macro language is like referring to a Ferrari as a means of getting from A to B. While it's basically a true statement, it hardly does justice to the product or to the sophistication of the technology involved. With VBA, like the Ferrari, you'll get from A to B faster and more stylishly, and you'll be in demand! (Unlike a Ferrari, though, VBA isn't red.)

* For a fast-paced introduction to VBScript, see Learning VBScript, by Paul Lomax, published by O'Reilly & Associates.

t It's able to do this because the ASP Server object, rather than VBScript, instantiates objects and provides support for automation. See Active Server Pages in a Nutshell, by Keyton Weissinger, due from O'Reilly & Associates in early 1999.

What Is VBA? 5

Let's look at how VBA has become the first almost universally accepted application customization language.

Was this article helpful?

0 0


  • seren
    Is vba in demand today?
    8 years ago
  • pauliina
    Is VBA an object oriented language?
    8 years ago

Post a comment