Using VBA macros in CorelDRAW
This tip has been written for CorelDRAW® Graphics Suite X3. While similar features might be available in previous releases the tip will be fully applicable to CorelDRAW Graphics Suite X3 and newer versions only.
Macros are recorded series of actions that let you perform tasks quickly. The macros in CorelDRAW® are based on Microsoft® Visual Basic® For Applications (VBA), which is included in the installation of CorelDRAW® Graphics Suite.
You can take advantage of the VBA macros available in the program, and you can record your own macros to automate tasks that you perform frequently. Recording macros is easy — you don't need to know VBA to get started.
Simple VBA macros let you complete basic operations, such as saving files to a different file format or drawing shapes. However, VBA can also be used to create richer macros and applications to help you with complex tasks. For example, using the Calendar Wizard included in the program, you can create multi-page and single-page custom calendars in different languages.
If you want to access your favorite macros quickly, you can add buttons to your workspace.
To run a VBA macro
1. Click Tools > Visual Basic > Play.
2. From the Macros in list box, choose All Standard Projects to view available macros.
A list of the macros included in CorelDRAW Graphics Suite
3. In the Macro name box, click a macro, and then click Run.
The names of the macros suggest their use. For example, Converter.Start lets you convert multiple files to a different file format. CorelMacros.CreateColorSwatch lets you generate rectangles filled with the colors of the color palette that you choose.
To record a macro
1. Click Tools > Visual Basic > Record.
2. In the Save Macro dialog box, type a name in the Macro name box. Also, you can add a short description in the Description box.
The Save Macro dialog box
3. From the Store macro in box, choose GlobalMacros.gms, and click OK.
Note that you can save the macro with your project (Graphic1 in the following example), or you can save it to GlobalMacros.gms, which is an open global macro storage (.gms) file. Storing a macro with your project lets you reuse the macro only in this project; storing a macro in the GlobalMacros.gms module makes it available in any CorelDRAW project.
The Save Macro dialog box
4. Perform the actions you want to record. For your first macro, you can begin by drawing and filling a few simple shapes and adding drop shadows as shown in the following example.
5. Click Tools > Visual Basic > Stop.
To try out your new macro, follow these steps:
1. Delete all shapes from your project.
2. Click Tools > Visual Basic > Play.
3. From the Macros in list box, choose GlobalMacros.gms.
4. In the Macro name box, click the macro name (RecordedMacros.MacroTest in the following example), and then click Run.
Note that the names of all recorded macros start with RecordedMacros.
The newly recorded macro is displayed in the CorelDRAW Visual Basic for Applications Macros dialog box.
Running the macro will add the shapes back to the drawing window.
If you want to delete the macro, you can select it in the CorelDRAW Visual Basic for Applications Macros dialog box, and then click Delete.
1. Click Tools > Customization.
2. In the Customization list of categories, click Commands.
3. From the Commands list box, choose Macros, and select the macro you want.
The Commands page of the Options dialog box. The chosen settings are indicated in red.
4. On the General tab, write the tooltip text for the button in the Tooltip Help box, and drag the macro name to a toolbar in the program window. When a black handle appears, release the mouse button.
Dragging the macro name to the standard toolbar
A button for the test macro has been added to the standard toolbar. When you point to the button, the tooltip is displayed.
To learn more about VBA and VBA macros, you can consult the CorelDRAW VBA Help and the VBA Programming Guide for CorelDRAW Graphics Suite.
- To access the CorelDRAW VBA Help, click Tools > Visual Basic > Visual Basic Editor, and press F2. In the Object browser, choose CorelDRAW from the Library list box, and press F1.
- To access the VBA Programming Guide for CorelDRAW Graphics Suite, on your Windows taskbar, click Start > All programs > CorelDRAW Graphics Suite > Documentation.