Chapter 28. Manipulating Visual Basic Components

In This Chapter

This chapter covers a topic that some readers might find extremely useful: writing Visual Basic for Applications (VBA) code that manipulates components in a VBA project. Read on to discover the following:

  • An overview of the VBA Integrated Development Environment (IDE) and its object model

  • How to use VBA to add and remove modules from a project

  • How to write VBA code that creates more VBA code

  • How to use VBA to help create UserForms

  • A useful function that creates a UserForm on the fly

The VBA IDE contains an object model that exposes key elements of your VBA projects, including the Visual Basic Editor (VBE) itself. This object model enables you to write VBA code that adds or removes modules, generates other VBA code, or even creates UserForms on the fly.

Introducing the IDE

The IDE is essentially an Object Linking and Embedding (OLE) automation interface for the Visual Basic Editor. After you establish a reference to the object, you have access to all the VBE’s objects, properties, and methods, and you can also declare objects from the IDE’s member classes.

Use the VBE’s Tools Introducing the IDE References command to display the References dialog box, where you can add a reference to the Microsoft Visual Basic for Applications Extensibility Library (see Figure 28-1). This gives you access to an object called VBIDE. Creating a reference to VBIDE

Get Excel® 2007 Power Programming with VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.