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 the preceding section “Loading VBA Project Files”).

2.    Open the IDE, and choose View ^ Project Explorer if the Project Explorer window isn’t already displayed. Click Module1. The Code window for Module1 opens.

3.    Enter the following code:

tmp757e-73_thumb

Analysis of this code is given in Listing 2.2 at the end of this sequence of steps.

4.    Choose File ^ Close And Return To AutoCAD. The IDE closes, and you are returned to the AutoCAD window.

5.    Choose Tools ^ Macro ^ Macros. The Macros dialog box appears, containing your macro.


6.   Click Run. Your application starts up just as if you had run it from the IDE.

7.   Click the command button with the Caption property set to Close. The application’s window disappears, and it is unloaded from memory.

Listing 2.2: Application Startup Macro

Listing 2.2: Application Startup Macro

Analysis

•    Line 1 starts the procedure RunMetricTolmperialConverter.

•    Line 2 calls the Show method from UserForml that displays this UserForm and runs the application until the user clicks the command button with the Close caption.

•    Line 3 ends the procedure.

Summary

Now that you have worked your way through this topic, you should

•    Know what a macro is.

•    Be able to develop macros to call VBA functions or to start an application.

•    Know how to run a macro from the AutoCAD window or the IDE.

•    Know how to call the Date and Time functions.


•    Be able to load project files manually, to run each time a particular drawing is opened or each time AutoCAD starts up.

Next post:

Previous post: