CorelDRAW Community
CorelDRAW Community
  • Site
  • User
  • Site
  • Search
  • User
Developer Area
Developer Area
Docs & Tutorials Macro Management in CorelDRAW Graphics Suite and CorelDRAW Technical Suite
  • Forums
  • Wikis
  • API References
  • Tags
  • More
  • Cancel
  • New
Developer Area requires membership for participation - click to join
  • +Addons: Extending Application Functionality with VBA and VSTA
  • -General Articles
    • Controlling CorelDRAW or Corel DESIGNER Applications From Other Processes
    • Creating Color Palettes
    • Creating Custom Outline Enhanced Pattern Styles
    • Creating VBA Macros with User Interface in CorelDRAW and Corel DESIGNER
    • Macro Management in CorelDRAW Graphics Suite and CorelDRAW Technical Suite
    • Storing Custom Information in Documents
    • Using Corel Query Language (CQL) to Search for Objects in CorelDRAW and Corel DESIGNER Documents
    • Using JavaScript with CorelDRAW

Macro Management in CorelDRAW Graphics Suite and CorelDRAW Technical Suite

The applications comprising CorelDRAW Graphics Suite 2019 and CorelDRAW Technical Suite 2019 (CorelDRAW, Corel PHOTO-PAINT and Corel DESIGNER) come with macro capabilities that allow you to extend their functionality. Macros are small programs/routines that let you perform repetitive tasks or add extended functionality that is not supported out of the box.
Macros can be created, loaded, played, and shared by using the Scripts docker.

Scripts docker

Displaying the Scripts docker

The Scripts docker is accessible by clicking Tools > Scripts > Scripts (or by pressing Alt+Shift+F11).

When shown, the Scripts docker appears on the right-hand side of the application window and displays the list of modules and available macros. The macro selection varies depending on the version of the application installed as well as the installed custom and user macros.

Executing a macro

To execute a macro, locate it in the list, select it, and click the Run button   at the bottom of the docker, or simply double-click the macro. For example, the CreateChart macro is available in CorelDRAW and Corel DESIGNER.

When this macro is executed, it creates a new document containing a list of color swatches for the document palette or the default color palette (as shown in the following illustration).

Editing existing macros

Macros are created and edited by using the Visual Basic for Applications editor. In order to see the source code of a macro, select the macro in the Scripts docker, right-click it, and select Edit from the pop-up menu. To edit Corel macros included with the suite, you must have administrative rights to the computer. You don't need administrative rights to edit macros that you recorded or created.

This will open the Visual Basic for Applications editor and allow you to see and edit the source code of the macro.

You can edit macros, write new ones, or delete them altogether.

Creating new macros

A macro is a single unit of functionality that is added to the host application (CorelDRAW, Corel DESIGNER, or Corel PHOTO-PAINT). A macro can be a simple action such as creating an object on a page or changing the attributes of the current selection, or it can provide a very complicated feature with its own User Interface and complex functionality. For example, the CalendarWizard in CorelDRAW allows users to create multipage calendars.

Generally, a macro can be thought of as a single command that can be executed by clicking a button in the application toolbar or by selecting a corresponding menu item.
Several related macros can be packaged in a single project and distributed as one unit (file). Macro projects are saved in files with a .gms extension (short for Global Macro Storage). Macro projects can also be embedded in documents.
In order to create a new GMS file for your new macros, you need to select New > New Macro Project menu in the Scripts docker.

You will be presented with the Save As dialog box, where you can specify the location and name of your GMS file. Note that if you select a non-default location for the GMS file, it will not be loaded automatically the next time the application is started.
After you specify the name and location of the GMS file, the new macro project will appear in the Scripts docker.

Within a macro project, macros are grouped logically into modules that let you keep related macros together. To create a new module, select a macro project in the Scripts docker, and select New > New Module (or right-click a macro project and select New Module from the pop-up menu).
To create a new macro, select a macro module, and select New > New Macro from the menu.

As soon as you do, a new macro is created and the macro editor window appears, letting you edit the code of the macro.

To give it a try, edit the new macro as shown below (applies only to CorelDRAW or Corel DESIGNER).

Sub Macro1()
ActiveLayer.CreateArtisticText ActivePage.CenterX, ActivePage.CenterY, _
"Hello, world!", Alignment:=cdrCenterAlignment
End Sub

Close the editor window, go back to the Scripts docker, select Macro1 from the list, right-click it, and click Run.

As soon as you run the macro, an artistic text object (Hello, world!) is created in the middle of the current page.

Distributing macros

Sharing your own macros

You can share your custom macros with other users by distributing the macro project (.gms) files.  The simplest way to share your macros is to save the macro project to a folder that is easily accessible. Select the project you want to share in the Scripts docker, right-click it, and select Copy To from the pop-up menu.

A new dialog window opens and lets you copy the macro module to a .gms file in a folder of your choice. From there, you can share the file with other users in your preferred way (email it, upload to a web site, etc.).

Loading macro project files

Loading files manually

If you have a GMS file with macros that you want to use, you simply need to click Load in the Scripts docker. The Load dialog box will appear, letting you select the GMS file to load. Once loaded, the macro project will appear in the Scripts docker, and you can run or edit its macros as usual.
Note that macro projects loaded this way will stay loaded until you shut down the application. When the application is restarted, the macro projects loaded manually will not be reloaded.
If you want to unload a macro project when you no longer need it, simply right-click the macro project in the Scripts docker, and click Unload Macro Project.

Load macro projects automatically

If you want a macro project to be loaded automatically when the host application is started, you must place it in a designated folder. When the host application starts, it loads all .gms files it finds in two special folders. One folder is used for standard macro projects that are shipped with the applications and is located inside the suite installation directory (it is usually read-only and requires administrative rights on the computer to copy files to). The other folder is used for storing user macros. The location of each folder depends on the application and its installation location as shown in the following table.

Application
Standard folder
User Folder
CorelDRAW Graphics Suite 2019
CorelDRAW
32-bit: C:\Program Files (x86)\Corel\CorelDRAW Graphics Suite 2019\Draw\GMS
64-bit: 32 bit: C:\Program Files \Corel\CorelDRAW Graphics Suite 2019\Draw\GMS
C:\Users\<user>\AppData\Roaming\Corel\CorelDRAW Graphics Suite 2019\Draw\GMS
Corel PHOTO-PAINT
32-bit: C:\Program Files (x86)\Corel\CorelDRAW Graphics Suite 2019\PHOTO-PAINT\GMS
64-bit: 32 bit: C:\Program Files \Corel\CorelDRAW Graphics Suite 2019\PHOTO-PAINT\GMS
C:\Users\<user>\AppData\Roaming\Corel\CorelDRAW Graphics Suite 2019\PHOTO-PAINT\GMS
CorelDRAW Technical Suite 2019
Corel DESIGNER
32-bit: C:\Program Files (x86)\Corel\CorelDRAW Technical Suite 2019\PHOTO-PAINT\GMS
64-bit: 32 bit: C:\Program Files \Corel\CorelDRAW Technical Suite 2019\PHOTO-PAINT\GMS
C:\Users\<user>\AppData\Roaming\Corel\CorelDRAW Technical Suite 2019\PHOTO-PAINT\GMS
CorelDRAW
32-bit: C:\Program Files (x86)\Corel\CorelDRAW Technical Suite 2019\Draw\GMS
64-bit: 32 bit: C:\Program Files \Corel\CorelDRAW Technical Suite 2019\Draw\GMS
C:\Users\<user>\AppData\Roaming\Corel\CorelDRAW Technical Suite 2019\Draw\GMS
Corel PHOTO-PAINT
32-bit: C:\Program Files (x86)\Corel\CorelDRAW Technical Suite 2019\PHOTO-PAINT\GMS
64-bit: 32 bit: C:\Program Files \Corel\CorelDRAW Technical Suite 2019\PHOTO-PAINT\GMS
C:\Users\<user>\AppData\Roaming\Corel\CorelDRAW Technical Suite 2019\PHOTO-PAINT\GMS

Saving macro source code

A macro project file (.gms) is a binary file which must be opened in the corresponding host application, such as CorelDRAW or Corel PHOTO-PAINT, and edited in the Visual Basic for Applications editor.
However, you can extract the plain-text source code of individual macro modules and save them as Visual Basic files (.bas).
In order to do this, select a macro module in the Scripts docker and click the Edit button at the bottom of the docker (or right-click the module and select Edit from the menu). This will open the VBA editor window. The selected module’s source code appears in the editor. You can save only the source code of this module by clicking File > Export File (Ctrl+E) in the VBA editor. You can also select the module in the VBA Editor’s Project Explorer window, right-click it, and select Export File from the menu.

If the Project Explorer window is not open in the VBA editor, press Ctrl+R to open it.

Embedding macros into documents

As mentioned earlier, a macro project can be embedded in documents (.cdr, .des, .cpt) files. There is a separate macro project item in the Scripts docker for each open document in the host application. You can add and edit macros in these macro projects as you would with regular .gms files.
When you save the document, the embedded macro project is saved along with it, inside the same file.
Macro projects embedded in documents appear at the end of the project list in the Scripts docker. Their names contain both the project name and the name of the documents they are embedded in. For example, the name VBAProject (Drawing.cdr) shows that the project name is VBAProject and the document name is Drawing.cdr.

Security considerations

Macros can pose a security risk. Macros can perform undesired actions when invoked so the user must explicitly allow for the macros to run. With stand-alone macro project files (saved in .gms files), the user must copy the files manually, run an installer, or explicitly load them through the Scripts docker. With macros embedded in documents, the situation is not as straightforward. A user might open a .cdr or .cpt file thinking they are opening a regular document, not realizing that the document contains macros.
Because of this security implication, when you open a document containing embedded macros, a warning dialog box is shown:

If you click Disable Macros, the document will open, but the embedded macros will be disabled and cannot be run. When you try to run a macro inside a disabled project, the following error message is shown.

If you click Enable Macros, the macro project is loaded, and the macros are available and can be executed and edited.

Integrating macros into user interface of application

Aside from accessing the macros through the Scripts docker, you can add them as buttons to the application’s user interface (on toolbars or menus). You can also assign shortcut keys to individual macros to quickly invoke them by simply pressing a key.
A keyboard shortcut can be assigned to a macro by right-clicking the macro in the Scripts docker and clicking Assign Keyboard Shortcut.

This will bring up the Customization dialog box with the Commands page open and the appropriate macro selected in the list of available macros:

Click in the New Shortcut Key box in the dialog box, and press the key combination you want to use to trigger this macro. Then, click Assign.
To customize the button image, use the Appearance tab of the dialog to specify a custom image, and type the caption text of the macro button.

You can select an image by clicking Browse.

When you add caption text, this text is used to identify the macro in the user interface of the application.

By dragging the macro out of the Customization dialog box onto a toolbar or menu, you will add a macro button to the user interface.

  • Share
  • History
  • More
  • Cancel
Related
Recommended

© Corel Corporation. All rights reserved. The content herein is in the form of a personal web log ("Blog") or forum posting. As such, the views expressed in this site are those of the participants and do not necessarily reflect the views of Corel Corporation, or its affiliates and their respective officers, directors, employees and agents. Terms of Use / Privacy​ ​/ ​Cookies / Terms and Conditions / User Guidelines.