Writing macros

Before you can begin writing a macro, you must create a Global Macro Storage (GMS) file — also known as a project file — for it. A GMS file is stored in its application's GMS folder, which is typically located at X:\Program Files\Corel\CorelDRAW Graphics Suite X3\<application>\ (where X is the letter that corresponds to the drive to which you've installed CorelDRAW Graphics Suite X3). The VB Editor stores all of the modules for that project in the project's GMS file.

Each project that you create can contain several modules. The Project Explorer (see page 17) presents each module type in its own folder. You cannot move a module from one folder to another within the same project, but you can drag a module to another project to make a copy of it there. There are four types of modules:

• CorelDRAW X3 Objects or Corel PHOTO-PAINT X3 Objects — used mostly for event handling, contains a single item (ThisMacroStorage or ThisDocument, respectively) and should not be used for normal code

• forms — used for custom dialog boxes and user interfaces, including the code to control them

• modules — used for general code and macros

• class modules — used for object-oriented Visual Basic classes (which are not discussed in this manual) After you create a GMS file, you can change its project name and add modules to it.

To write the macro, you must use the VB Editor. Macros that are developed in the VB Editor can take advantage of full programming control, including conditional execution, looping, and branching. In effect, you can write macros that are programs in their own right. (For the purposes of this manual, however, all VBA code is referred to as a macro even though, in some contexts, a macro is just those parts of that code that can be launched by CorelDRAW or Corel PHOTO-PAINT.)

To create a project file

1 Close the application (that is, CorelDRAW or Corel PHOTO-PAINT) for which you want to create the project file.

2 In Windows Explorer, navigate to the GMS folder for the application for which you want to create the project file.

A new, empty text document is created in this folder.

4 Rename the file as <filename> .gms, where <filename> is any valid Windows filename.

5 Restart the application for which you've created the project file.

When you launch the VB Editor, the project file you've created is displayed in the Project Explorer as Global Macros (<filename> .gms).

To rename a project

1 In the Project Explorer, select the project you want to rename.

2 In the Properties window, edit the (Name) value.

Names must follow normal variable-naming conventions, so they must begin with an alphabetic character, and they must not contain spaces nor special characters other than underscores ( _ ).

3 Press Enter to commit your changes.

To add a module to a project

1 In the Project Explorer, right-click the project to which you want to add a module.

2 Click one of the following

• Insert ► Module — inserts a normal code module

• Insert ► UserForm — inserts a new form (that is, dialog box)

• Insert ► Class Module — inserts a new class code module

The new module is stored in the project's folder for that type of module.

+2 -1


  • bruno
    7 years ago
    Can corel draw takes macro?
    6 years ago
  • Alina
    How to write a macro in corel draw?
    6 years ago
  • mario
    How to programe gms file vba?
    4 months ago

Post a comment