Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate

Barry MacDonnell's
Toolbox for WordPerfect

Macros, tips, and templates for Corel® WordPerfect® for Windows®
© Copyright 1996-2017 by Barry MacDonnell. All Rights Reserved.

Page updated May 15, 2016

WordPerfect Tips
Main tips page | Browse tips
"Two-key" macros can help organize related macros or tasks under a common keystroke combination.

You then can use the same shortcut key combination (e.g., Alt+z) to play the macro, and then separately press any of several alphanumeric keys (e.g., "1") or menu choices to perform some action.
(Here: "<Alt+z>,1". You could then use "<Alt+z>,2" etc. for another task.)


Related pages -

"Two-tap macros" -
How to press a keyboard key twice in succession to perform a task, play another macro, etc.

Double duty macros - Make a key do "double duty" by assigning a macro to it, and make the macro play only if the key is struck multiple times (e.g., 3x, 4x, etc.)

NOTE: The following material should be considered a tutorial since it assumes you know how to edit simple macro code -- or at least carefully follow the instructions below and make changes to the code (e.g., to add your own text). To copy the macro code below to create a functioning macro in your WordPerfect program, see here for general instructions.

Here are some "2-key" macros for WordPerfect. They can be assigned to a keystroke combination. [For help assigning macros to keys, click here.]

Then you will only need to use a single shortcut key combination to start the macro and then separately press an assigned alphanumeric key (or menu choice) to do other things -- such as insert accented letters, perform a task, etc.

Tap, tap ... done!

The big advantage for such a macro is that you can just assign the two-key macro to a single shortcut key and reserve other shortcut keys for other things. Using the same shortcut key as a "gateway" to multiple functions makes it easy to remember, too.

Here are some examples.

•  When the first macro below is played it will wait for any alphanumeric key (as well as Backspace, Delete, and Ctrl+Enter) and then take whatever action is set up for that key in the CaseOf commands. (See instructions in the macro's code.) Note this example does not use a menu of choices  when the macro is played: you will need to remember what each key does.

•  The second macro below uses the Char() command to display a small dialog and get the second keystroke. It will then take whatever action is set up for that key in the CaseOf commands. (The example simply inserts an accented letter such as "à".) Note this example's dialog also acts as a reminder about what to do and what will happen when you press the next key.

•  The third macro below, written by Roy Lewis and posted on WP Universe, uses mnemonically labeled push buttons on a menu as the second keystroke. (The example then executes various other code routines that you can either record and paste into the macro code, or write and insert into the macro code, in place of the existing Type() commands.)

•  The fourth macro below (similar to #3, but with simpler code) uses push buttons on a menu to apply UPPER case, Initial Caps, or lower case to the current word or selection of text.

•  The fifth macro below (a variation of #4) uses push buttons on a menu to insert various closings for letters ("Sincerely yours," etc.) with a pick-list choice of sender name.

•  Another macro on this site, QWIKSET ("Quickly set relative font sizes and other attributes with a keystroke") uses a push-button menu, where the push buttons can also be "pushed" with a keyboard key -- making the macro a "2-key" macro. You press a key combination (e.g., <Alt+Z>) then press a second letter or number. With QwikSet, this causes the macro to dismiss the menu and execute the command.


SAMPLE MACRO #1

[To copy this macro into your WordPerfect, see here.]

// Macro begins here -

OnCancel(End@)
OnError(End@)

PauseKey(Any!) // Wait for any key to be pressed

// Depending on which key is pressed, carry out the
// action(s) below -
Switch(?PauseKey)

// Note the following 6 choices. They are intended to
// demonstrate the general command format.

// However, if the macro is played "as is," the keys would
// simply cause the macro to terminate, so you must insert
// macro commands that perform some action after
// (to the right of)
each CaseOf command.

// Note that since there is a Default command at the end of
// all commands to terminate the macro, any keys that are
// not assigned to a CaseOf statement will cause the macro to end.

CaseOF ("0"):
CaseOF ("1"):
CaseOF ("2"):
CaseOF ("a"):
CaseOF ("b"):
CaseOF ("c"):
// ... etc.

// The following Default command executes if the second key
// is something other that a key specified in the CaseOF
// commands above

Default: vKey:=?Pausekey

MessageBox(; "No key assigned"; "The second key you just pressed, < " +vKey+ " >, has not been assigned to this macro." +NToC(0F90Ah)+ "Edit this macro and assign the key inside the macro's Switch command.")
Return

Endswitch

Label(End@)
Return

// Macro ends here

If, for example, the macro had this CaseOf statement -

CaseOF ("q"): If(?Substructure) SubstructureExit Endif
                     CloseNoSave()
                     Go(End@)

- and the macro was saved and assigned to the <Ctrl+k> keys, then pressing <Ctrl+k><q> would cause the current file to be closed without saving it (i.e., it would "quit" the file). (Remember WordStar? This is one of WordStar's commands.)


SAMPLE MACRO #2

The next macro is slightly less complicated, and has the virtue of prompting the user with a simple dialog box. However, some people are annoyed with such a dialog, and may prefer the first dialog-less macro above.

Note that the accented letters used in the CaseOf commands shown in the example below were entered using the numeric keypad.

For example, the è between the quote marks in the third Type() command was entered using <Alt+0232> on the numeric keypad. A list of the numerical values for these special characters can be found in the Windows character map (Start, Programs, Accessories, System Tools, Character Map).

You can make a copy of the macro's code and change the grave accent (`) marks to acute accent (´) marks. Save and compile the macros and assign each macro to separate shortcut keys, both of which are easy to remember.

Also see the Tip below.

[To copy this macro into your WordPerfect, see here.]

// Macro begins here -

OnCancel(End@)
OnError(End@)

Char(nextc; "Enter an uppercase or lowercase vowel: ")

vKey:=NToC(nextc)

Switch(NToC(nextc))

CaseOf "a":  Type("à")
CaseOf "A":  Type("À")
CaseOf "e":  Type("è")
CaseOf "E":  Type("È")
CaseOf "u":  Type("ù")
CaseOf "U":  Type("Ù")

Default:               MessageBox(; "No key assigned"; "The second key you just pressed, < " +vKey+ " >, has not been assigned in this macro." +NToC(0F90Ah)+ "Edit this macro and assign the key inside the macro's Switch command.")   
Return

EndSwitch

Label(End@)
Return

// Macro ends here

Assign the macro to a shortcut key and then, when the macro plays, enter the base letter in the small field on the pop up dialog. (No Enter key is needed, but a Cancel button is available.)

Alternative

See the macro, EZMenu, which can be set up with a main menu with choices that open one or more sub-menus.

Tip - Inserting accented characters

With Windows Vista/7 the macro command SendKeys() -- which has the ability to send keystroke combinations to the program -- is effectively broken. You have to disable the User Access Control (UAC) in those versions of Windows to make such text/symbol keystrokes work (script commands such as {Ctrl} or {Alt} still will not work). Disabling the UAC is something that is not generally recommended.

Therefore ...

Since the Sample Macro #2 above is designed to insert various accented letters, the letters were entered in the macro code's Type() commands with the numeric keypad using an <Alt+nnn> combination, as explained above. This technique works in most other word processors or text editors.

However, you might want to know that there are alternative ways to create accented characters directly in the document without using a macro with Switch..CaseOf..Endswitch commands or one with pop-up dialog prompts, as demonstrated above.

Alternatives:

☼  From Derek Duke on WordPerfect Universe:

"... free open-source alternative [to AllChars, below] which works in much the same way is available for those with Windows 7 or later:
WinCompose - https://github.com/SamHocevar/wincompose

☼  From Charles Rossiter, Corel C_Tech:

1. "Get an International Keyboard, or apply [in Control Panel, Keyboard] the US International keyboard definition to a standard US keyboard. This then works in all applications. ...

2. In WPWin, create a series of keyboard keystrokes. For example, I use Alt+e for e-acute, Ctrl+Shift+E for E-grave, Alt+a for a-umlaut, Alt+Shift+O for O-umlaut, Alt+Shift+C for C-cedilla, etc. There is no conflict with other Alt-key shortcuts (eg Alt+a for T_a_ble): Alt+a gives a-umlaut; Alt,a gives T_a_ble (i.e., press and release the Alt key, then press a)."

Note: To use the second method (assign the accented letter to a key combination), follow the steps outlined here (see especially the section, "For keystrokes").

3. Use a utility such as the free program, AllChars, at http://allchars.zwolnet.com/. See the Introduction link on the home page for more information. (Not tested by this author, but recommended by other knowledgeable WordPerfect users.)

☼  A more broadly useful program (not free, but a trial version is available) is As-U-Type at http://www.asutype.com/, which works well with WordPerfect's QuickCorrect, too.


SAMPLE MACRO #3

[Tip: See Samples #4 and #5 for simple push-button macros without Callback routines. They might be easier to modify by those without macro writing or editing experience.]

The macro below is by Roy ("lemoto") Lewis's macro on WordPerfect Universe at http://www.wpuniverse.com/vb/showthread.php?postid=40594#post40594.

When a button is pushed (i.e., your second keystroke or a mouse click) from the macro's main pop up dialog, this example macro types a word corresponding to the button's label into the document. Hence, you will need to modify the macro's menu and other commands (such as the Callback/Switch routine and the branching area) to perform your own tasks, but those familiar with writing WordPerfect macros should have little trouble doing this.

[To copy this macro into your WordPerfect, see here.]

vDoIt=""

DialogDefine ("Choose";85;60;74;93;Modeless!+Percent!; "Select Task -")
DialogSetProperties ("Choose"; "MS Sans Serif"; 8p)
DialogAddPushButton ("Choose";"DirBttn";2;3;72;13;0;"&Change Directory")
DialogAddPushButton ("Choose";"FileBttn";2;18;72;13;0;"&File Labels")
DialogAddPushButton ("Choose";"GenBttn";2;32;72;13;0;"&Generate Tables")
DialogAddPushButton ("Choose";"DateBttn";2;47;72;13;0;"Change Letter &Date")
DialogAddPushButton ("Choose";"OKBttn";2;62;72;13;OKBttn!;"&Labels and Envelopes")
DialogAddPushButton ("Choose";"CancelBttn";2;80;72;11;CancelBttn!;"Abort")

DialogShow ("Choose";"WordPerfect";cb)
DoQuit=False
CallbackWait
If(DoQuit=True) Return EndIf
DialogDestroy("Choose")

Go(Indirect(vDoit))

cb:

If(cb[5]=274 OR cb[3]="CancelBttn")
DoQuit=True
CallbackResume
Return
EndIf

If(cb[5]=273)
SWITCH(cb[3])
CaseOF "DirBttn":
vDoit="Directory"
CaseOF "FileBttn":
vDoit= "FileLabels"
CaseOF "GenBttn":
vDoit= "Generate"
CaseOF "DateBttn":
vDoit= "LetterDate"
CaseOF "OKBttn":
vDoit= "Mail"
ENDSWITCH
CallbackResume
EndIf
Return

//===
Directory:
HardReturn Type("// Testing: "+vDoIt) Return
FileLabels:
HardReturn Type("// Testing: "+vDoIt) Return
Generate:
HardReturn Type("// Testing: "+vDoIt) Return
LetterDate:
HardReturn Type("// Testing: "+vDoIt) Return
Mail:
HardReturn Type("// Testing: "+vDoIt) Return

Assign the macro to a shortcut key and then, when the menu appears press the desired mnemonic key (underlined letter) for a "two key" macro, or click the push button.


SAMPLE MACRO #4

[Similar to #3 -- but simpler since it does not use a Callback routine. See also #5.]

The following material -- plus the separate function described in Footnote 1 -- has been incorporated into a downloadable multiple-choice macro on this side, Convert Case. It can be used as a "2-key" macro, too.

Here is a two-keystroke macro to apply UPPER case, Initial Caps, or lower case to the current word or a selection of text when a button is pushed (i.e., the second keystroke) on the pop up dialog.

[Note: Since WordPerfect's built-in conversion of text to all lower case leaves the first word of every sentence capitalized, see Footnote 1 below for a different macro that can convert all selected text to lower case.]

Assign the macro to a shortcut key and then, when the menu appears, press "u", "i", or "l". (Or press "a" to abort.)

The word(s) will then be toggled to UPPER case, Initial Caps, or lower case. (See note #1 below.)

If you do not select anything before playing the macro, it will select the current word if the cursor is on, or just after, a word.

Notes

1. If you have selected an all-upper case (or initial capped) word that begins a sentence, it will still have its first letter capitalized when "lower case" is chosen. (This also happens when you use the Edit, Convert Case menu in WordPerfect)

2. Note also that the word(s) will remain selected after you play the macro to let you further process the selection. If this is not desired, remove the two slash marks from the front of the SelectOff command.

[To copy this macro into your WordPerfect, see here.]

// Macro begins here

OnCancel(EndItNow@)

// First, if nothing is selected, select the current word:
If(?BlockActive=False) SelectWord Endif
Display(On!) // (turn on so we can see selection on screen)

// Display a "push button" menu:
DialogDefine ("CT";50;50;75;75;Percent!;"Case Toggle")
DialogAddPushButton ("CT";101;2;3;70;14;0;"&UPPER case")
DialogAddPushButton ("CT";102;2;19;70;14;0;"&Initial Caps")
DialogAddPushButton ("CT";103;2;35;70;14;0;"&lower case")
DialogAddPushButton ("CT";104;7;55;60;14;0;"&Abort")
DialogShow ("CT";"WordPerfect";;104)

// Store the menu choice and use it in the Switch command:
vAns:=MacroDialogResult
Switch(vAns)
CaseOF 101: ConvertCaseUppercase
CaseOF 102: ConvertCaseInitialCaps
CaseOF 103: ConvertCaseLowercase
Endswitch

// Exit here:
Label(EndItNow@)
// If you want to de-select the item after it is processed
// remove the leading slash marks from the next command:
//SelectOff

Return
// Macro ends here

Tip

If you use Initial Caps in titles and headlines, see the style tip here.


SAMPLE MACRO #5

[A variation on the technique used in #4.]

Here is a two-keystroke macro to insert a letter's closing at the current cursor location. Notice that it adds a horizontal graphics line above the person's name to underline their signature.

You will want to change the person names ("David Smith" et al) in the DialogAddPushbutton commands and also in the Switch commands.

Assign the macro to a key and then, when the menu appears, press the button to insert the name or press "a" to abort.

[To copy this macro into your WordPerfect, see here.]

// Macro begins here
OnCancel(EndItNow@)
Display(On!)
// Display a "push button" menu:
DialogDefine ("Choices";50;10;80;75;Percent!;"Closings:")
DialogAddPushButton ("Choices";101;2;3;75;14;0;"&David Smith")
DialogAddPushButton ("Choices";102;2;19;75;14;0;"&Susan Doe")
DialogAddPushButton ("Choices";103;2;35;75;14;0;"Sally &Jones")
DialogAddPushButton ("Choices";104;10;55;60;14;DefaultBttn!|CancelBttn!;"&Abort")
DialogShow ("Choices";"WordPerfect")
// Store the menu choice and use it in the Switch command:
vAns:=MacroDialogResult
If(vAns=2) Quit Endif

// Start the closing:
Type("Sincerely yours,")
HardReturn HardReturn HardReturn HardReturn

// Add a signature line:
GraphicsLineCreate ()
GraphicsLineSpacing (TopSpace: 0.0"; BottomSpace: 0.05")
GraphicsLineLength (Length: 3.0")
GraphicsLineHorizontalPosition (Position: Left!)
GraphicsLineEnd (State: Save!)
HardReturn

// Insert the name:
Switch(vAns)
    CaseOF 101:  Type("David Smith, Jr.")
                        HardReturn
                        Type("President and CEO")
    CaseOF 102:  Type("Susan Doe")
    CaseOF 103:  Type("Sally Jones")
Endswitch
HardReturn 

// Exit here:
Label(EndItNow@)
Return
// Macro ends here

[Page Top]


Footnote 1

[Referenced in Sample #4 above...]

Some of the following material (particularly the code in Sample macro #6) has been incorporated into a downloadable multiple-choice macro on this side, Convert Case.

WordPerfect's built-in conversion to all lower case (e.g., Edit, Convert Case, Lower case -- or the macro equivalent, ConvertCaseLowercase) still leaves the first word of every sentence capitalized, so if you have large blocks of text and you want all of it to be in lower case, either of the following macros should do the job.

[Always make a backup of your document first. To copy a macro from an Internet site (like this one) see here.]

The first macro is a "brute force" approach that looks at each character in the selection and, if it is upper case, it converts it to lower case, then it proceeds to the next character. It stops when it encounters a user-defined "terminator" character (here, the Greek omega symbol; all WordPerfect symbols are seen as "characters" by macros).

The second (and newer) macro is more elegant since it first converts the selection to lower case using the built-in command, ConvertCaseLowercase; then it removes remaining upper case letters with a Search/Replace routine (which uses a 2-dimension array).

One virtue of these approaches is that they preserve all existing formatting, since they only change upper case characters to lower case characters, skipping over any formatting codes. [A small, three-command macro that can do the same thing and remove all formatting at the same time was posted by Roy ("lemoto") Lewis on 02/24/09 in the Corel WPX4 newsgroup: SelectAll vT = ToLower(?SelectedText) Type(vT).]

The general methods used might be useful in other macros.

SAMPLE MACRO #6

Important

This macro uses the Greek omega symbol (8,50) where indicated with ? symbols below, as a "terminator" to tell the macro when to stop. You should insert this symbol using WordPerfect's Insert, Symbol (choose the Greek set, symbol number 8,50) in place of the ? symbols shown between the double quote marks in both the Type() and While() commands below.

You can use any character symbol that is not used elsewhere in the document. The omega symbol was an arbitrary choice for this macro on the assumption it probably would not exist in most users' documents.

It might take some time to finish converting characters in a very large document and/or on some systems. You should see its progress in the WordPerfect status bar. You can always stop it by right-clicking the WordPerfect "cassette" icon in your system tray at the bottom right of your desktop. [Sample macro #6 below is probably faster in must situations.]

[To copy this macro into your WordPerfect, see here.]

// Macro begins here:

// Converts all UPPER case characters to lower case
// in a large SELECTION of text.

// First, if nothing is selected, select the current word:
If(?BlockActive=False) SelectWord Endif

// Next, bookmark the selection:
BookmarkCreate("TempMarker")
BookmarkBlock("TempMarker")
PosBlockBottom
SelectOff

// Add a "terminator" character (from symbol set 8,50):
Type("
?") // <= use WP symbol 8,50 here
BookmarkBlock("TempMarker")
PosBlockTop
SelectOff
BookmarkDelete("TempMarker")

// Step through the selection:
While(?RightChar<>"
?") // <= use WP symbol 8,50 here
// If it's a code or anything other than
// an upper-case character, skip it:
If(?RightCode>0 OR StrIsChar(?RightChar;;NotEqualTo!;UpperCase!))
PosCharNext
Else
SelectCharNext
vSel:=StrTransform(?SelectedText;
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
"abcdefghijklmnopqrstuvwxyz")
Type(vSel)
EndIf
Endwhile

// Clean up - delete the terminator symbol:
DeleteCharNext
Return

// Macro ends here

[Page Top]


SAMPLE MACRO #7

Like the previous macro, this macro will convert the current word -- or everything in a selection of text -- to lower case, including capitalized words at the beginning of every sentence, the pronoun "I," etc.

It uses a different and more efficient apporach than Sample macro #5 above. It also should be faster than #5.

[To copy this macro into your WordPerfect, see here.]

// Macro begins here:

Display(Off!)
// First, if nothing is selected, select the current word:
If(?BlockActive=False)
SelectWord
Wait(10)
Endif
If(?SelectedText="") // (in case SelectWord failed to select anything)
Display(On!)
Messagebox(;"Ooops!";"Select some text first!")
Quit
Endif

// Note: It is quicker overall to use this command first:
ConvertCaseLowercase

// Create a temporary bookmark to let us reselect the selection:
BookmarkCreate("Temp_Marker")
BookmarkBlock("Temp_Marker")
PosBlockTop

// Reset the Find & Replace settings to factory default:
pResetFindReplace ()
// Set some new search and replace conditions:
SearchInSelection(Yes!)
SearchCaseSensitive(Yes!)
ReplaceWithCase (Yes!)
NotFound(Off!)

// Store search and replace items in an array:
change[] = {
{"A";"a"};
{"B";"b"};
{"C";"c"};
{"D";"d"};
{"E";"e"};
{"F";"f"};
{"G";"g"};
{"H";"h"};
{"I";"i"};
{"J";"j"};
{"K";"k"};
{"L";"l"};
{"M";"m"};
{"N";"n"};
{"O";"o"};
{"P";"p"};
{"Q";"q"};
{"R";"r"};
{"S";"s"};
{"T";"t"};
{"U";"u"};
{"V";"v"};
{"W";"w"};
{"X";"x"};
{"Y";"y"};
{"Z";"z"}}

// Process the selection:
ForNext(i;1;change[0]/2;1)
SearchString (change[i;1])
ReplaceString (change[i;2])
BookmarkBlock("Temp_Marker")
PosBlockTop
While(True)
SearchNext()
If(?NotFound=1)
Break // (exit from this While loop)
EndIf
ReplaceWithCase (Yes!)
ReplaceCurrent
Endwhile
EndFor

// Clean up and exit:
BookmarkBlock("Temp_Marker")
PosBlockBottom
// If you want to de-select the item after it is processed
// remove the leading slash marks from the next command:
//SelectMode(Off!)
BookmarkDelete("Temp_Marker")
pResetFindReplace ()

Return

// --- Procedures here: ---
// Reset Find and Replace parameters for the Search/Replace commands:
Procedure pResetFindReplace ()
SearchString ("")
ReplaceString ("")
// Only one of these 4 Match commands can be active at any one time:
// MatchPositionAfter ()
// MatchExtendSelection()
// MatchPositionBefore()
MatchSelection()
SearchFindWholeWordsOnly (No!)
MatchWithAttributes (No!)
ReplaceWithAttributes (No!)
SearchCaseSensitive (No!)
ReplaceWithCase (No!)
MatchWithFont (No!)
ReplaceWithFont (No!)
MatchWithFontSize (No!)
ReplaceWithFontSize (No!)
SearchInSelection (No!)
SearchWordForms (No!)
SearchWrap (No!)
MatchLimit (No!)
EndProcedure

// Macro ends here

[Page Top]