WordPerfect lets you create three types of macros:
WordPerfect-is stored in the document it applies to or in a macro library file. Create this macro when your task is contained within WordPerfect.
PerfectScript-is stored with a .wcm filename extension. This macro is useful if you want to interact with other WordPerfect Office applications, such as Quattro Pro and Corel Presentations.
Visual Basic for Applications (VBA)-lets you develop scripts that are saved in specific projects that use a robust version of the Visual Basic programming language. You can access the VBA editor from WordPerfect.
You can use macros to perform repetitive or complex tasks automatically. A macro performs a series of instructions. For example, you can create a macro that retrieves a file, gives it a new name, and saves it to another format. You can then play the macro to repeat the action.
A macro can consist of keystrokes, programming commands, product commands, and comments.The simplest way to create a macro is to "record" the keystrokes in WordPerfect. You can also write a macro if you want to include non-recordable tasks. (For example, you can define a macro to play until a certain event happens.)
In this section, you'll learn about:
using QuickMacros
recording, saving, and storing macros
playing macros
using macros included with WordPerfect
using toolbars for macros
using template macros
editing and deleting template macros
triggering macros from templates
customizing WordPerfect macros
assigning template macros to keystrokes, menus, and toolbars
associating toolbars with template features
writing and editing macros using PerfectScript
understanding macro commands and syntax
using macro conventions and formatting macros
recording macro commands into macros
inserting codes in macros
using macros from earlier versions of WordPerfect
using programming commands in macros
using parameters in macros
using variables in PerfectScript
using the macro command browser
using macro commands to retrieve information
using OLE object commands in macros
compiling macros
working from the PerfectScript utility
testing for errors from PerfectScript
editing and deleting macros
searching in macros
integrating with Microsoft Visual Basic for Applications
using the PerfectScript class to change WordPerfect documents
working with VBA methods
accessing and manipulating applications from other applications
using OLE Automation
understanding OLE Automation
using files with DDE Execute from previous versions of WordPerfect
getting online Help for macros
WordPerfect Office contains a minimal set of macros. To access more macros, visit our OfficeCommunity site on the World Wide Web.
Using QuickMacros
WordPerfect lets you create QuickMacros. A QuickMacro is a temporary macro that you can record without saving. WordPerfect stores a QuickMacro in your computer's memory for the current WordPerfect session only.
When you record a new QuickMacro, the existing QuickMacro is replaced. You cannot edit a QuickMacro or save it to a template.
To record a QuickMacro
1 Click Tools Template macro Record.
2 Click Record without entering a macro name in the Name box.
3 Perform the task you are recording.
4 Click Tools Template macro Record to stop recording the macro.
Note
WordPerfect records both the keyboard and mouse actions you make; however, you must use the keyboard instead of the mouse to position the cursor in the document window.
To play a QuickMacro
1 Click Tools Template macro Play.
2 Click Play without entering a macro name in the Name box.
Recording, saving, and storing macros
Macros automate application tasks. For example, WordPerfect macros automate tasks, such as setting margins, selecting a font, or creating a merge file. Macro tasks consist of instructions, called statements. There are several kinds of statements: assignments, conditions, loops, comments, and commands. For example,
MarginLeft (1.0")
MarginRight (1.0")
are WordPerfect commands that set one-inch left and right margins. Each command represents one instruction or statement. The simplest macro consists of only one statement. Complex macros have hundreds of statements. The sequence of statements determines how a macro performs its tasks.
One way to create a macro is to record a task in WordPerfect. When you record a macro, you convert actions into macro commands. These are stored until you need them. Use the fewest number of steps necessary to perform your task.
To include programming commands, or non-recordable actions, you must edit the macro after you record it. For more information about editing macros, see "Editing and deleting macros."
You can instruct WordPerfect to pause while playing a macro if you want the macro to stop playing. This can be useful if you want to allow users time to type in text when they run the macro. When you play the macro, it runs until it reaches the PauseKey command.
WordPerfect allows you to store macros in any folder, including the default and supplemental macros folders. The default macros folder contains the macros with which WordPerfect was shipped. By default, WordPerfect's shipping macros are stored in X:\program files\corel\WordPerfect Office 11\macros\wpwin, where X represents the drive letter. You can use the supplemental macros folder as an additional folder to store macros.
To record a macro
1 Click Tools Macro Record.
A check mark beside the Record command indicates that the command is enabled.
2 Type a name for the macro in the Filename box.
3 Click Record.
4 Perform the actions you want to record.
You can also
Pause recording a macro Click Tools Macro Pause.
Resume recording a macro Click Tools Macro Pause.
Stop recording a macro Click Tools Macro Record.
A check mark beside the Pause command indicates that the command is enabled.
Notes
A macro is saved with a .wcm filename extension.
If you are recording a new macro, clicking Undo will still retain the step that you tried to undo.
To change the default macros folder
1 Click Tools Settings.
2 Click Files.
3 Click the Merge/macro tab.
4 Click the Browse button in the Default macro folder box.
If you want to change the supplemental macros folder, click the Browse button in the Supplemental macro folder box.
5 Choose the drive and folder where you want to store the macros.
Playing macros
WordPerfect allows you to play and pause the play of macros. You can play a macro to repeat the sequence of steps for a task you want to perform. Before you can play a macro, however, it must be compiled with a compiler. For more information, see "Compiling macros."
To play a macro
1 Click Tools Macro Play.
2 Choose the folder where the file is stored.
3 Double-click the macro filename.
Notes
The Macro submenu displays the last nine macros you have played.
A macro you record may not play properly in every situation. Some macros depend on certain options or settings. When a macro cannot play, a message may display, indicating the reason and the line number(s) in the macro you can check.
Tip
You can pause or resume playing a macro by clicking Tools Macro Pause.
To play a macro multiple times
1 Click Edit Repeat next action.
2 Type a value in the Number of times to repeat next action box.
If you want WordPerfect to use this value as a default, click Use as default.
Using macros included with WordPerfect
WordPerfect comes with many predefined macros. The macros included with WordPerfect Office can be used as a basis for writing your own macro. For more information, see "Writing and editing macros using PerfectScript."
Many of the macros can be played by clicking buttons on the Shipping macros toolbar. For more information, see "Using toolbars for macros." For more information about playing macros, see "Playing macros."
Macros included with WordPerfect
Macro Description
abbrev.wcm Lets you insert the expanded forms of QuickWords.
adrs2mrg.wcm Copies the address book (for automated templates) into a merge data file.
allfonts.wcm Creates a document that lists every font available to the current printer and shows sample text in each font.
checkbox.wcm Inserts a check box in the document that you can click to add or remove a check mark.
closeall.wcm Closes all open documents and prompts you to save the modified ones.
ctrlm.wcm Activates the macro command browser.
cvtdocs11.wcm Lets you convert multiple documents from another document type to WordPerfect 11 format.
dcconvert.wcm Converts "whole word" drop caps to "number of characters" drop caps for conversion to Microsoft Word.
endfoot.wcm Converts endnotes to footnotes in the document or selected text. To run this macro, your cursor must be outside of the footnote or endnote box (that is, your cursor must be in the main body of the page).
expndall.wcm Expands all QuickWords in the document.
filestmp.wcm Places the filename and path of the current document in a header or footer.
flipenv.wcm Creates an envelope rotated 180 degrees (text is upside down). On printers with a large trailing margin, this lets you print the return address 0.25" from the edge.
fontdn.wcm Decreases the font size of the selected text by 2 points.
fontup.wcm Increases the font size of the selected text by 2 points.
footend.wcm Converts footnotes to endnotes in the document or in selected text.
longname.wcm Changes the name of selected documents from the DOS (8.3) filename to a long filename based on the document summary description.
parabrk.wcm Inserts symbols or small graphics as paragraph breaks. The graphics are centered on the blank line between paragraphs.
pleading.wcm Creates lines and numbers for pleading documents.
prompts.wcm Helps you create prompts for automated templates.
reverse.wcm Creates white text on black background (or uses other color combinations) in selected text or table cells.
saveall.wcm Prompts you to save open documents.
savetoa.wcm Saves the current document and makes a copy of it on the diskette in drive A.
tconvert.wcm Converts WordPerfect 6.0 templates that used the _autofil.wcm macro.
uawp11en.wcm Used by PerfectExpert. Do not delete this macro from the macros folder.
wp_org.wcm Creates an organization chart in WordPerfect.
wp_pr.wcm Sends a WordPerfect outline to Corel Presentations.
Note
In order to run the footend.wcm or endfoot.wcm macros, your cursor must be outside of the footnote or endnote box (that is, your cursor must be in the main body of the page).
Using toolbars for macros
WordPerfect has toolbars associated with macros, which you can use to: stop, record, play, and pause macros; insert system variables, product commands, and programming commands; save and compile a macro; insert merge and find and replace codes; change how a macro is saved; or close a macro.
To view a macro toolbar
1 Click Tools Settings.
2 Click Customize.
3 In the Customize settings dialog box, click the Toolbars tab.
4 In the Available toolbars list box, enable any of the following check boxes:
Macro tools
Shipping macros
To view the Macro toolbar
Click Tools Macro Macro toolbar.
A check mark beside the Macro toolbar command indicates that the command is enabled.
Note
To access commands on the Macro toolbar or the Template macro toolbar, you must press ALT + SHIFT and the letter on the desired button. For example, to access the Codes button command, you must press ALT + SHIFT + O.
A check mark beside the Template macro toolbar command indicates that the command is enabled.
To use the Macro toolbar
Click To
Stop Stop recording or playing a macro
Record Begin recording in the current document
Play Play the current macro
Pause Pause while recording or playing a macro
Dialog Editor Display the editor for customizing dialog boxes
Commands Insert system variables, product commands, and programming commands at the cursor
Save & Compile Save and compile the macro
Codes Insert merge and Find & Replace codes
Options Change how the macro is saved, close the macro, or hide the Macro toolbar
Using template macros
WordPerfect lets you add macros to a template. Template macros are macros attached to a template and are saved as part of that template file. They can be played only from that template and are not listed with standard macros.
There are three ways to add a macro to a template: you can add a template macro from another template; add a macro from a macro file stored on disk; or record a template macro from scratch.
You can record macros for specific templates and select specific templates as the default location to which you can record macros. You can only view the macros saved with the current template.
You can play a template macro. WordPerfect includes several templates with macros that are ready to use. You can pause a template macro if you need to interrupt the macro you are playing. You cannot play a template macro until you save and exit the template to which it is attached.
You can pause while playing a template macro. This can be useful if you want to allow users time to type in text when they run the template macro.
To add a template macro from another template
1 Click File New from project.
2 Choose a category from the Category list box.
3 Choose a template from the Project list box.
4 Click Options Edit WP template.
5 Click the Copy/remove object button on the Template toolbar.
6 In the Copy/remove template objects dialog box, choose the template that contains the macro from the Templates to copy from list box.
7 Choose Macros from the Object type list box.
If you want to add a macro from a macro file stored on disk, choose Macros on disk from the Object type list box, click the Browse button in the Macros on disk area, and choose the drive and folder in which the macro is stored.
8 From the Source list box, choose the macro you want to copy.
9 Click one of the following:
Copy-copies only selected items in the Source list box
Copy all-copies all items in the Source list box
Tip
If the Template toolbar is not displayed, click View Toolbars, and enable the Template check box.
To record a template macro from scratch
1 Click Tools Template macro Record.
2 Type the name of the macro in the Name box.
3 Click Location.
4 Enable one of the following options in the Macro location dialog box:
Current template-specifies the current template to record a template macro to
Default template-specifies the default template to record a template macro to
If you want to record a template macro to the enabled location by default, enable the Use as default check box.
5 Click OK.
6 Click Record.
7 Perform the task you want to record.
You can also
Pause a template macro you are recording Click Tools Template macro Pause.
Resume recording a template macro Click Tools Template macro Pause.
Stop recording a template macro Click Tools Template macro Record.
View the macros that are saved with the current template Click Tools Template macro Play.
The macros saved with the current template are listed in the Macros in template list box.
Note
If you are recording a new macro, clicking Undo does not undo the most recent step performed; you will still retain the step that you tried to undo.
To play a template macro
1 Click File New from project.
2 Choose a category from the Category list box.
3 Choose a template from the Project list box.
4 Click Create.
5 Click Tools Template macro Play.
6 Choose a macro from the Macros in template list.
The macro name displays in the Name box.
7 Click Play.
You can also
Pause a template macro Click Tools Template macro Pause.
Resume playing a template macro Click Tools Template macro Pause.
Play a template macro multiple times Click Edit Repeat next action, and type a value in the Number of times to repeat next action box.
Tip
If you want to use the Number of times to repeat next action value as a default, click Use as default.
Editing and deleting template macros
By editing template macros, you can add, edit, or delete macro commands. The same rules of syntax and conventions that apply to macros apply to template macros. For more information, see "Writing and editing macros using PerfectScript," "Compiling macros," and "Editing and deleting macros."
To edit a template macro
1 Click File New from project.
2 Choose a template from the Project list box.
3 Click Options Edit WP template.
4 Click Tools Template macro Edit.
5 Choose a template macro from the Macros in template box.
6 Click Edit.
7 Edit any macro commands.
8 Click the Save & compile button on the Template macro toolbar.
9 Click Options Close macro on the Template macro toolbar.
Tip
To display the Template macro toolbar, click Tools Template macro Template macro toolbar.
To delete a template macro
1 Click Tools Template macro Edit.
2 Choose a template macro from the Macros in template box.
3 Click Delete.
Note
You cannot delete template macros that are assigned to a toolbar, keyboard, or menu. WordPerfect deletes template macros from a template when you remove them from a toolbar, keyboard, or menu.
Triggering macros from templates
You can play a macro as you use a template. For example, if you use a template to create letters, you can set a PRE PRINT trigger in the template that runs a spell-check macro. The macro then lets you check the spelling of your letters just before they print.
You can use the following macro triggers.
Trigger Description
POST CLOSE Runs in the active window after you close a window.
POST NEW Runs after you open a window by clicking File New.
POST OPEN Runs after you open a window by clicking File Open.
POST PRINT Runs after you send a print job to the printer.
POST STARTUP Runs when you start WordPerfect. The macro must be associated with the default template.
POST SWITCH DOC Runs in the active window after you switch from another window.
POST TABLES Runs after you create a table structure in a document, but before you enter data in the table.
PRE CLOSE Runs before you close the active window by clicking File Close.
PRE NEW Runs in the active window before you open another window by clicking File New.
PRE OPEN Runs in the active window before you open another window by clicking File Open.
PRE PRINT Runs after you click File Print, but before the print job is generated.
PRE SWITCH DOC Runs in the active window before you switch to another window.
PRE TABLES Runs after you insert a table by clicking Insert Table, but before the table structure is created in the current window.
Adding the TemplateFill macro command
The TemplateFill() macro command displays a dialog box that lets you enter template data. This dialog box varies depending on the fields required for the current template. If personal information is not specified, this command first prompts you to specify personal information regardless of what data the current template requires. If the current template does not require data other than personal information, and the personal information has been set, this command updates the personal information in the document without displaying the dialog box. If the current document is not based on an automated template, and the personal information has been set, this command does nothing.
Only macros that have been added to the template can be used with triggers. A trigger specifies when a macro plays in a template (for example, before you close a document).
Macros on disk cannot be associated with a trigger. Running the Prompt Builder associates the POST NEW trigger with <dofiller>, the feature that runs the Prompts dialog box. If the POST NEW trigger is associated with a template macro, use the TemplateFill() macro command in that template macro to activate the DoFiller feature.
If you want DoFiller to run when you are using a template macro, you need to add the TemplateFill macro command. The position of this command is important because macro execution is generally sequential. For example, if you want to insert a macro in a template that adds a date code to your document, you need to let the macro place the date code prior to your filling out the template prompts.
To insert a macro trigger in a template
1 Click File New from project.
2 Choose a template from the Project list box.
3 Click Options Edit WP template.
4 Click the Associate button on the Template toolbar.
5 Enable the Triggers option.
6 Choose a trigger from the Items to associate list box.
7 From the Macros list box, choose the macro you want to associate with the trigger.
Note
Only template macros that you have created in that template or copied to that template display in the Macros list box.
To add the TemplateFill macro command
1 Click Tools Macro Edit.
2 Double-click a filename.
3 Press CTRL + END to place the cursor at the end of the macro document.
4 Press ENTER.
5 Type TemplateFill().
6 Click Save & compile on the Template macro toolbar.
7 Choose the drive and folder where you want to save the macro.
8 Type the filename in the Filename box.
9 Click Options Close macro on the Template macro toolbar.
Customizing WordPerfect macros
You can assign macros to keystrokes, menus, toolbars, and the property bar.
WordPerfect allows you to edit the name and QuickTips of a button, edit button images, and change the macro triggered by a button.
To assign a macro to a keystroke
1 Click Tools Settings.
2 Click Customize.
3 In the Customize settings dialog box, click the Keyboards tab.
4 Choose a keyboard from the Available keyboards list, and click Edit.
If you want to create a keyboard with the same initial settings as an existing keyboard, choose a keyboard, click Create, and type a name in the New keyboard name box.
5 In the Choose a shortcut key list box, choose a key to which you want to assign the template macro.
6 Click the Macros tab.
7 Click Assign macro to key.
8 In the Select macro dialog box, type the filename and path in the Filename box.
9 Click Select.
Note
If you save a macro file without its full path, WordPerfect searches for the macro in the default folder, as specified on the Document page of the Files settings dialog box.
To assign a macro to a menu
1 Click Tools Settings.
2 Click Customize.
3 In the Customize settings dialog box, click the Menus tab.
4 Choose a menu from the Available menus list box.
5 Click Edit.
6 Click the Macros tab.
7 Click Add macro.
8 In the Select macro dialog box, type the filename and path in the Filename box.
9 Click Select.
You can also
Place the macro in a menu Drag the new macro item over the menu. The blue line represents the macro.
Create a menu with the same initial settings as an existing menu Click the Menus tab, and choose a menu from the Available menus list. Click Create, and type a name for the new menu in the New menu name box.
To assign a macro to a toolbar button
1 Click Tools Settings.
2 Click Customize.
3 Choose a toolbar from the Available toolbars list box.
4 Click Edit.
5 Click the Macros tab.
6 Click Add macro.
7 Type the macro path and filename in the Filename box.
8 Click Select.
To edit the name and QuickTips of a button
1 Right-click a button, and click Edit.
2 Right-click the button you want to edit, and click Customize.
3 Type text in any of the following boxes:
Button text-edits the text of the button
QuickTip-edits the QuickTips text of the button
Note
If you save a macro file without its full path, WordPerfect searches for the macro in the default folder, as specified on the Document page of the Files settings dialog box.
To edit the image of a macro button
1 Right-click a button, and click Edit.
2 Make changes in any of the following areas:
Colors-lets you change the color of the button
Drawing mode-lets you choose between changing the image a single pixel at a time or filling the whole area
Zoomed image-lets you re-create the image
To assign a macro to the property bar
1 Click Tools Settings, and click Customize.
2 Click the Property bars tab.
3 Choose a property bar from the Available property bars list box.
4 Click Edit.
5 Click the Macros tab.
6 Click Add macro.
7 Type the macro filename and path in the Filename box.
8 Click Select.
9 Drag the button that represents the macro to the property bar.
Assigning template macros to keystrokes, menus, and toolbars
You can assign template macros to a keystroke, a menu, and a toolbar button. When you press the assigned keystroke, click a menu item, or click a toolbar button, the macro is launched. You can assign template macros by using macros that you have created or macros that are included with WordPerfect.
You can also edit the current menu and create a menu with the same initial settings as an existing menu.
To assign a template macro to a keystroke
1 Click File New from project.
2 Choose a template from the Project list box.
3 Click Options Edit WP template.
4 Click Tools Settings, and click Customize.
5 Click the Keyboards tab.
6 Choose a keyboard from the Available keyboards list, and click Edit.
7 Choose a key in the Choose a shortcut key list box.
If you want to remove a template macro from a keystroke, choose a key to remove from the template macro from the Choose a shortcut key list box, and click Remove assignment.
8 Click the Macros tab, and click Assign template macro to key.
9 Click a macro in the Macros in template list box, and click Select.
To create a keyboard with the same initial settings as an existing keyboard
1 Click File New from project.
2 Choose a template from the Project list box.
3 Click Options Edit WP template.
4 Click Tools Settings, and click Customize.
5 Click the Keyboards tab.
6 Choose a keyboard from the Available keyboards list, and click Create.
7 Type a name for the new keyboard in the New keyboard name box.
8 Click Location.
9 Enable one of the following options:
Current template-saves the keyboard in the current template
Default template-saves the keyboard in the default template
To assign a template macro to a menu
1 Click File New from project.
2 Choose a WordPerfect template, and click Options Edit WP template.
3 Click Tools Settings, and click Customize.
4 In the Customize settings dialog box, click the Menus tab.
5 Choose a menu from the Available menus list, and click Edit.
6 Click the Macros tab, and click Add template macro.
7 Choose the template macro from the Macros in template list, and click Select.
8 Click OK.
9 Drag the button that represents the template macro to the menu.
To edit the current template menu
1 Right-click the current template menu.
2 Click Settings.
3 Click Edit.
To create a template menu with the same initial settings as an existing menu
1 Click File New from project.
2 Choose a category from the Category list box.
3 Choose a template from the Project list box.
4 Click Options Edit WP template.
5 Click Tools Settings, and click Customize.
6 In the Customize settings dialog box, click the Menus tab.
7 Choose a menu from the Available menus list, and click Create.
8 In the Create Menu Bar dialog box, type a name for the new menu in the New menu name box.
9 Click Location, and enable one of the following options:
Current template-saves the menu in the current template
Default template-saves the menu in the default template
To assign a template macro to a toolbar button
1 Click File New from project.
2 Choose a category from the Category list box.
3 Choose a template from the Project list box.
4 Click Options Edit WP template.
5 Click Tools Settings, and click Customize.
6 Click the Toolbars tab, enable a toolbar in the Available toolbars list box, and click Edit.
7 In the Toolbar editor dialog box, click the Macros tab, and click Add template macro.
8 In the Select template macro dialog box, click a macro in the Macros in template list box.
9 Click Select.
If you want the macro to display in a menu, drag the new macro menu item over the menu of your choice to the position you want. The blue line represents the macro.
To edit a toolbar button
1 Right-click any button, and click Edit.
If you want to customize a button, make any changes in the Toolbar editor dialog box.
2 Right-click the button you want to edit, and click Customize.
3 In the Customize button dialog box, type text in any of the following boxes:
Button text-edits the text of the button
QuickTip-edits the QuickTips text of the button
To edit the image of a toolbar button
1 Right-click any button, and click Edit.
2 Right-click the button you want to edit, and click Customize.
3 In the Image editor dialog box, click Edit, and make changes in any of the following areas:
Colors-allows you to change the color of a button
Drawing mode-allows you to choose between changing the image a single pixel at a time or filling the whole area
Zoomed image-allows you to re-create an image
Associating toolbars with template features
You can display a specific toolbar when you are working with specific features and macros. Toolbars, menus, and keyboards can be associated with a predefined list of features, which can be activated when the particular feature is used in a document.
You can also associate macros with various triggers that execute when a particular event occurs inside WordPerfect. There are 13 predefined triggers that you can associate with macros (for example, PRE NEW, POST NEW, PRE PRINT, and POST PRINT). For a list of macro triggers, see "Triggering macros from templates."
To use the Associate button with a template macro
1 Click File New from project.
2 Choose a category from the Category list box.
3 Choose a template from the Project list box.
4 Click Options Edit WP template.
5 Click the Associate button on the Template toolbar.
6 Enable the Triggers option.
7 Choose a trigger from the Items to associate list box.
8 Choose a macro from the Macros list box.
Note
Only template macros that you have created in that template or copied to that template display in the Template macros list box.
Writing and editing macros using PerfectScript
PerfectScript macros are the common macro language for all applications in WordPerfect Office. PerfectScript is a command-based language. When you record a macro, you record the results of keystrokes or mouse selections instead of recording the keystrokes themselves. For example, instead of recording each keystroke required to change the top margin of a page to 2" (5.1 cm), the macro records the following command:
MarginTop(MarginWidth:2.0")
Recording and playing macros can speed up routine tasks, but the real power of macros is tapped when product commands are used together with PerfectScript programming commands. By using product commands and programming commands, the functionality of WordPerfect Office features is combined with the customizing, decision making, and iterative capabilities of a programming language. Using programming commands also makes it possible to include the functionality of other applications.
A written macro can include non-recordable statements, which cannot be included in recorded macros, that specify how a macro performs a task. You specify conditions for playing assignments, loops, and programming commands. Writing a macro provides greater flexibility to determine function than recording a macro. You can create a macro in WordPerfect and play it in the application for which it was written.
With PerfectScript, you can combine statements to automate routine tasks and simplify large ones. You write the macro using statements, compile the macro, and play the macro.
The PerfectScript programming language consists of WordPerfect application commands and functions, and programming statements and functions. PerfectScript can do more than perform your recorded WordPerfect commands-it can extend the functionality of WordPerfect in a number of ways, such as prompting you for input, displaying messages, controlling other Corel and Windows-based applications, and performing and repeating commands. You can also build complete applications or wizards so that, if you have limited experience using WordPerfect, you can still use some of the more complex actions.
PerfectScript lets you record, play, compile, and convert macros for all WordPerfect Office applications. PerfectScript starts automatically when you record or play a macro. If you play a macro for an application that is not running, PerfectScript automatically starts the application.
Installing the Software Developer's Kit
The Software Developer's Kit (SDK) is a set of tools that lets you customize WordPerfect Office applications for commercial or business use. For information about acquiring a WordPerfect Office Software Developer's Kit, visit Corel Solutions Partners.
The SDK includes the following components:
online Help for the SDK
OLE automation samples
PerfectScript tools
tools and utilities, including code generation wizards for third-party add-ons to WordPerfect, Quattro Pro, and Corel Presentations; utilities to monitor events in WordPerfect and Corel Presentations; and a file format parsing tool
Understanding macro commands and syntax
To edit and write macros, you must understand the PerfectScript programming language and the principles of computer programming. For most users, recording macro commands is more efficient than typing commands into the macro. WordPerfect opens a new blank window with another macro bar. After you have recorded keystrokes or commands, WordPerfect returns to the macro you are editing and inserts the newly recorded commands.
When you create macros using the macro command browser, the macro commands appear in a separate document, numbered. The first line of the macro identifies the program and default language that it uses. The remainder of the macro performs the reported instructions.
For more information about macro commands, see "Using macro conventions and formatting macros."
Understanding components of macro commands
Macro commands consist of four parts: a command name, parameters, enumerations, and separators. The table and example below display and describe these elements of syntax.
Macro command component Description
Command name Indicates which feature the command activates. Some commands consist only of a command name, such as FileOpenDlg().
Parameters Provides more information about the command, such as which options of a feature are active. Parameters are always enclosed in parentheses; for example, Backup (State:On!).
Enumerations Sets the value of a parameter (for example, State: On! or State: Off!). Enumerations always end with an exclamation point.
Separators Marks the parameters in a command. Semicolons separate individual parameters; parentheses enclose a series of parameters; and braces enclose a series of repeating parameters.
The command in the above example has two parameters: TargetPage and Adjust. They are separated by a semicolon. Adjust is a repeating parameter with two enumerations specified: FitLeftMargin and FitLineSpacing. All the Adjust parameters are enclosed in braces to group them.
When you create macros using the macro command browser, the commands are inserted in the correct format. If you type a macro without the macro command browser, you must arrange macro commands and their elements in a precise order or syntax. Each macro command must be spelled correctly and must include all the required parameters and separators.
Using types of macro commands
There are three types of macro commands: product commands, OLE object commands, and programming commands. Product commands are specific to a product, such as WordPerfect or Quattro Pro. OLE object commands perform tasks on an OLE object. Programming commands work across applications; they are PerfectScript commands.
Command names often describe an action, such as Font, MarginLeft, Advance, and FootnoteOption, in WordPerfect; AlignObjectsLeft, BitmapBlur, SelectAllObjects, and ToolbarCopy in Corel Presentations; or Range in Microsoft Excel. Command names are not case sensitive and usually do not contain spaces. Exceptions include programming commands that call a subroutine, such as Case Call or OnCancel Call.
A macro can use more than one application product and OLE object. Commands to the non-default application or OLE object require a prefix, which is specified in an application or object statement. For example,
A1.AboutDlg ()
A1 (followed by a period) is the prefix. It tells the compiler to use the application or Object assigned A1 in a PerfectScript application or Object statement.
Understanding syntax
Syntax refers to the grammatical rules that govern the form of macro statements and expressions. For example, the syntax of the following statement, which types "John Doe," is correct:
Type(Text: "John Doe")
The syntax of the next example is incorrect and produces an error message because the statement lacks a closing parenthesis:
Type(Text: "John Doe"
If you find it difficult to distinguish different parts of a macro, remember that you can add extra line spaces, tabs, and even font changes to make the macro more readable. As long as the commands are written correctly, the macro compiler ignores extra spaces and lines.
Using macro conventions and formatting macros
When you create macros in WordPerfect, you must follow macro conventions for the macro to compile properly. However, you do not need to observe macro formatting conventions for a macro to compile correctly. These conventions are designed to improve the readability of your macro.
Macro conventions
Macro command syntax must be correct for a macro to compile. Understanding the following conventions used in WordPerfect macros will help you avoid common syntax errors:
You can enter programming commands in uppercase, lowercase, or mixed case. The compiler is not case sensitive. Product commands, such as AboutDlg or AddSlide, are shown in mixed case. WordPerfect system variables begin with ?, such as ?TextColorRed or ?FontUnderline. They are shown in mixed case, and they return information about the application environment.
Line wrapping does not affect macro execution. You should not insert spaces in a command name unless the space is part of the syntax. Do not use hard returns, tabs, or indents in a character expression (a character string enclosed in double quotation marks). You can use spaces, tabs, indents, and hard returns before and after commands, or between parameters, to make a macro easier to read. SmartQuotes in a macro create a compile-time syntax error. For more information about SmartQuotes, see "Editing quotation marks."
Formatting macros
You can type commands into a macro that is saved in a file or in a template. If you want to improve the readability of a macro, you can format it so that it includes tabs, spaces, and even font or text appearance changes. Formatting the macro does not affect how it works. For example, WordPerfect records the following macro in this format:
PosDocBottom()
Type(Text:"Sincerely")
HardReturn()
HardReturn()
HardReturn()
HardReturn()
Type(text:"Mrs. Jane Doe")
HardReturn()
Type(Text:"Vice President, Marketing")
However, if you type the commands yourself or edit an existing macro, you can format the macro the way you want. For example, you can format it as follows:
PosDocBottom()
Type(Text:"Sincerely")
HardReturn()
HardReturn()
HardReturn()
HardReturn()
Type(text:"Mrs. Jane Doe")
HardReturn()
Type(Text:"Vice President, Marketing")
Recording macro commands into macros
WordPerfect lets you record macro commands in a macro.
To record macro commands in a macro
1 Click where you want to insert the macro command.
2 Click Tools Macro Record.
3 Type a name for the macro in the Filename box.
4 Click Record.
A blank document displays.
5 Perform the actions you want to record.
6 Click the Stop button on the Macro toolbar.
WordPerfect returns you to the macro document with the new macro command you recorded inserted.
Inserting codes in macros
When you insert a code in a macro, you must use straight double quotation marks around the code so that WordPerfect recognizes the code in the macro.
To insert a code in a macro
1 Click Tools Macro Macro toolbar.
2 Click Codes on the Macro toolbar.
3 Click one of the following tabs:
Search-allows you to select search find codes
Merge-allows you to select merge find codes
Date-allows you to select date find codes
Other-allows you to select chapter, page, section page, total page, and volume number find codes
4 Choose a code from the Find codes list.
5 Click Insert.
6 Click Close.
Using macros from earlier versions of WordPerfect
You can update macros from earlier versions of WordPerfect. The structure of the macro language has not changed for WordPerfect versions 6 through 11. While later versions of the macro language include access to new WordPerfect features and some new commands for accessing existing features, most of the older product commands have been retained to maintain macro compatibility. Because some older product commands have changed, macros from versions 6 through 10 might need minor corrections when you compile them for the first time.
To update macros from earlier versions of WordPerfect
1 Click Tools Macro Edit.
2 Choose a macro.
3 Click Edit.
4 Make any changes.
5 Click Save & compile on the Macro toolbar.
6 Note any errors listed by the macro compiler and make changes as needed.
Using programming commands in macros
Programming commands work across WordPerfect Office applications. They control macro functions by
specifying conditions under which other macro commands or statements operate (for example, Case, IfElse, Endif, Switch, and EndSwitch)
For example,
If (x = "A")
LineHeightDlg
Else
LineSpacingDlg
Endif
displays the Line height dialog box in WordPerfect if x equals the value "A". If x has another value, the subroutine displays the Line spacing dialog box. The If, Else, and Endif commands are programming commands. LineHeightDlg and LineSpacingDlg are product commands.
repeating macro commands or statements a specified number of times or until certain conditions are met (for example, For, Endfor, Repeat, Until, While, or EndWhile)
invoking or jumping to a specified subroutine with Call or Go
Programming commands and product commands are not case sensitive.
You can add blank lines to separate programming commands and subroutines, and you can indent lines to show levels of nested commands. Some macro commands cannot be recorded. You must type or insert them using the macro command browser. For information about the macro command browser, see "Using the macro command browser."
Using parameters in macros
Commands often require parameters, which are constant values (data). Parameters are passed to the compiler (which translates the macro so that it can be played in the application) or passed between subroutines. In this WordPerfect command,
Advance (Where: AdvanceDown!; Amount: 1.0")
Advance is the command name, Where and Amount are parameters, and AdvanceDown! and 1.0" are parameter data. This command advances the cursor down one inch. Parameter names, such as Where and Amount, are optional.
Data types
A data type represents information that is needed by a parameter or returned by a command (return value).
In the command syntax, data types are displayed in italics. For example, the enumerations for the Rotation parameter of BoxCaption Rotation are Degrees90!, Degrees180!, Degrees270!, and None!. Only these enumerations can replace the data type in the command syntax. Enumerations are identified by a trailing exclamation point. The most common data types in product commands are string, enumeration, and numeric. Programming commands frequently use variables.
Parameter names
Using parameter names is optional. For example, InhibitInput (State: Off!) works just like InhibitInput (Off!). Some product commands have no parameters. Their syntax is usually written with empty parameters, such as PosScreenUp (). Some programming commands and all system variables have no parameters. Their syntax is the command name alone, such as Pause and ?FeatureBar.
Italics
Italics in macros syntax indicate parameter names or types to be replaced with data. For example, the syntax of GraphicsLineLength is:
GraphicsLineLength (Length: measurement)
After you replace measurement with a number, the command might be:
GraphicsLineLength (Length: 21)
or
GraphicsLineLength (21)
Punctuation
You must enclose parameters in parentheses. A missing parenthesis is a common error that prevents macros from compiling. Parentheses are optional for commands without parameters, but must be used with user-defined functions and procedures.
Spaces between command names and the opening parenthesis of the parameter section, and after semicolons in parameters, are optional.
You must separate multiple parameters with semicolons (;). If you omit an optional parameter, include the semicolon in the syntax to keep following parameters in their correct positions. For example,
Product commands perform product tasks in a specific application. For example,
ShowSlide(Slide: 4)
displays the fourth slide in the current slide show in Corel Presentations.
Product commands are specific for each application. They perform various functions in that application, such as
displaying a dialog box, InitialCodesStyleDlg
specifying settings, such as styles, BorderBottomLine; user settings, PrefZoom; or attributes, Font
enabling and disabling features, InhibitInput or TableCellIgnoreCalculation
performing actions, such as inserting a file, FileInsert or code, PrinterCommand; renaming a bookmark BookmarkRename; converting comments to text CommentConvert; or moving the cursor PosColBottom
playing macros that are included with the application AddressMergeShippingMacro
Product commands that report information (return value) about the state of an application or feature are sometimes called system variables. In WordPerfect, system variables begin with a leading question mark, ?ColumnWidth. In Corel Presentations, they begin with a leading Env (EnvPaths). Some system variables in Corel Presentations have parameters as well as return values.
Product commands and programming commands are not case sensitive.
Using variables in PerfectScript
A variable acts as a place holder that represents a value, which can be text, numbers, or measurements, that you can use repeatedly in a macro. You can change or manipulate this value in the macro. WordPerfect allows you to use the commands, such as Constant, Declare, Global, Indirect, Local, and Persist, to create variables with different functions and actions.
Variables are typically preceded by the letter "v".
To assign a variable in PerfectScript
Type the Assign macro command where you want to define the variable.
For example, type Assign (vName;"Lori") to assign the text "Lori" to the variable "vName".
Tip
You can type a colon followed by the equals sign (:=) as a shortcut to assigning a variable. For example, you could type vName:="Lori" for the above example.
Using the macro command browser
The macro command browser helps you insert macro product and programming commands in WordPerfect Office macros.
Product commands perform tasks that let you use WordPerfect Office features in macros. Many product commands require you to specify parameters and enumerations, which give the applications information about which options to use in dialog boxes and whether to hide or display certain features (for example, the ruler). You can use the macro command browser to specify the commands quickly.
To access macro commands
1 Click Tools Macro Macro toolbar.
2 Click the Commands button on the Macro toolbar.
The PerfectScript commands dialog box displays.
To insert commands with the macro command browser
1 Click Tools Macro Macro toolbar.
2 Click the Commands button on the Macro toolbar.
3 Choose a product from the Command type list box.
4 Choose items from any of the following list boxes:
Commands
Parameters
Enumeration
5 In the Command edit box type any additional parameters you need.
6 Click Insert.
7 Click Close.
Notes
You can also insert system variables with the macro command browser. System variables contain current system information, such as the current chart type or the default directory. In WordPerfect, system variables begin with a question mark.
A parameter that is displayed in bold is a required parameter. The macro will not compile or run without it.