Automating the Visual Basic Editor

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

In addition to using code to work with other Microsoft® Office applications, you can also use automation code to work with the objects exposed by the Microsoft® Visual Basic® Editor object model. You can use the Visual Basic Editor's object model to work with the objects in its user interface, such as its windows and command bars, which makes it possible for you to develop add-ins to customize and extend the Visual Basic Editor's user interface. Additionally, you can use the Visual Basic Editor's object model to work with your Microsoft® Visual Basic® for Applications (VBA) project itself to add and delete references, to set and read project properties, and to work with the components that make up your project, such as standard modules, class modules, and UserForms. This feature makes it possible for you to write code to maintain references, to document and set properties for projects, and to work with existing components and add new ones.

To work with the Visual Basic Editor's objects, first you must establish a reference to its type library, which is named Microsoft® Visual Basic® for Applications Extensibility 5.3. To write code to work with the Visual Basic Editor, you must initialize a variable to work with the Visual Basic Editor's top-level object, the VBE object. However, you can't reference the VBE object directly. This is because the Visual Basic Editor isn't an independent application or service; it's running as part of the host application's process. To initialize an object variable to work with the Visual Basic Editor, you must use the VBE accessor property of the host application's Application object. The VBE property is available in all Office applications except Outlook. The following example shows how to initialize an object variable to work with the Visual Basic Editor:

Dim objVBE As VBIDE.VBE
Set objVBE = Application.VBE

For an overview of working with the Visual Basic Editor's object model, see the Visual Basic Language Developer's Handbook by Ken Getz and Mike Gilbert (Sybex, 1999).

Note   The Microsoft® Access Application object provides a References collection and Reference object that make it possible for you to work with references in an Access VBA project without requiring you to establish a reference to the Microsoft Visual Basic for Applications Extensibility 5.3 type library. For more information about the Access References collection, search the Microsoft Access Visual Basic Reference Help index for "References collection."

See Also

Office Application Automation | Setting References | Object Variable Declaration | Creation of Object Variables to Automate Another Office Application | The Set Statement and the New Keyword in Automation | Single-Use vs. Multi-Use Applications | Using the CreateObject and GetObject Functions | Working with Documents That Contain Startup Code | Shutting Down Objects Created by Using Automation | Add-ins, Templates, Wizards, and Libraries