In this topic, you will learn how to create a simple VBA application through a series of tutorials. You will learn how to employ visual tools to create the graphical user interface, and write code to execute simple commands. You will also explore the basics of the Visual Basic environment by using its features to […]

The AutoCAD VBA Environment (Developing a Simple VBA Application)

The Visual Basic Editor is the integrated environment in which you develop all your VBA code. As you can see from Figure 1.1, the IDE has its own graphical user interface. Its windows provide all the tools required for creating, editing, debugging, and running your macros and applications. With this much functionality, the IDE is […]

Developing Your First Application (Developing a Simple VBA Application) (AutoCAD VBA) Part 1

For your first application, we’ll work with the Metric-Imperial Converter application, which converts metric measurements to imperial, and vice versa. This application uses two text boxes as shown in Figure 1.4. The interface allows the user to enter imperial measurements in yards into the first text box, then converts the measurement to metric and displays […]

Developing Your First Application (Developing a Simple VBA Application) (AutoCAD VBA) Part 2

Displaying the Code Window When double-clicked in the Project Explorer window, all the modules except UserForms will immediately display the Code window. When a UserForm is double-clicked, its graphical representation is displayed in the UserForm window. You must then doubleclick anywhere inside this UserForm window to display its Code window. Every Code window has a […]

What Is a Macro? (Creating VBA Macros) (AutoCAD VBA)

In this topic, you’ll learn about macros. You’ll see how to use them as stand-alone programs for completing simple tasks, as well as for running applications. You’ll also gain experience using the editing features of the IDE to help you enter code and to do the typing of code elements for you. A macro is […]

Creating a Macro to Add Text to a Drawing (AutoCAD VBA) Part 1

One of the things you do most frequently when you create a drawing is to add some text for a title, a label, your name, or simply the date and time the drawing was created. You probably routinely add the same kind of information to every drawing you create, so it would be nice to […]

Creating a Macro to Add Text to a Drawing (AutoCAD VBA) Part 2

Saving a Macro You already know that AutoCAD uses drawing files with the extension .dwg to save your drawings, and VBA uses project files with the extension .dvb to save all the components of your application from the IDE. These components include all your Visual Basic code, UserForms, and modules. Because the AutoCAD and VBA […]

Using VBA’s Date and Time Functions (Creating VBA Macros) (AutoCAD VBA)

Visual Basic provides numerous functions that you’ll find easy to use. This section introduces two of them—Date and Time—that may be useful to include in your DrawText macro. The Date function returns a Variant type containing the string representing the current date, and the Time function returns a Variant type containing a string representing the […]

Loading VBA Project Files (Creating VBA Macros) (AutoCAD VBA)

When you open a drawing file from the AutoCAD window, by default no VBA project file is loaded into memory. You’ll need to load your project file manually before you can edit or run your macros. This section shows you how to change that. If you prefer that your macros be loaded automatically, there are […]

Starting an Application from a Macro (Creating VBA Macros) (AutoCAD VBA)

A VBA application can be run directly from the AutoCAD window without opening the IDE, if you write a macro that will open the UserForm. 1.    If your Metric-Imperial Converter application isn’t loaded, choose Tools ^ Macro ^ Load Project in the AutoCAD window. Then select the project file where the application is stored (see […]