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-2024 by Barry MacDonnell. All Rights Reserved.

Page updated Dec 8, 2022

WordPerfect Tips
Main tips page | Browse more 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 one 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 -
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 that 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 various examples of macro code — or at least carefully follow the instructions below and make changes to the code (e.g., to add your own text and/or macro commands). If not, see here for general instructions.

Here are several "2-key" macros for WordPerfect.

They can be assigned to any available shortcut key to play them.

Then you will only need to

[1] use a single shortcut key to start the macro, and then

[2] immediately use a previously designated alphanumeric key or menu choice to do other things — such as insert accented letters, perform a task, etc.

Tap, tap
... done!

Advantages

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 (usually related) functions makes it easy to remember, too.

Tips

- You don't have to use two keys with some of the examples below. You could also use a toolbar button to start the macro with a mouse click, and then press a designated alphanumeric key — or in the case of a push-button menu, either a second key or a mouse click — to do some task such as play another macro, type some text, load a document, etc. See examples below.

- Or you could use a hyperlink to play the macro when the hyperlink is clicked.

Examples

•  When the first macro below is played it will pause and wait for any alphanumeric or punctuation key (as well as Backspace, Delete, Enter, 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, so you will need to remember what each key does.

•  The second macro below uses the Char() command to display a small dialog menu to get the second keystroke. It will then take whatever action is set up for that second key in the CaseOf commands. (The example simply inserts an accented letter into the document, 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.

Macros that use multiple push buttons for user choices:

•  The third macro below uses push buttons on a menu to apply UPPER case, Initial Caps, or lower case to the current word or selection of text.

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

•  The fifth macro below, written by Roy Lewis and posted on WP Universe and somewhat more advanced due to the use of a CallBack routine, 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.)

•  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, as with other pushbutton examples here, the second key press dismisses the menu and executes the command.

[Tip: Push button menus are good for many "two key" macros since either pressing the keyboard key corresponding to the button's underlined letter or number (e.g., x)
or clicking directly on the push button with your mouse immediately dismisses the menu and carries out the assigned task. See Footnote 2 for an example of a push button menu that was set up to use all 26 letter keys and 10 number keys. [While most users would not find that example practical — how will you remember what each of the 36 buttons does? the overall structure and the syntax of its commands might be useful in many other macros.]


  Sample macro 1

To copy this macro code into your WordPerfect to produce a functioning macro, see here.

// Macro begins here -

OnCancel(End@)
OnError(End@)

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

// Depending on which key is pressed (and thus stored in ?PauseKey),
// carry out the action(s) below in the CaseOf() commands -

Switch(?PauseKey)

// NOTE the first 6 alphanumeric key choices below.
// They are intended to demonstrate the general CaseOf()
// command format for those keys.
// [See the CaseOf ("q") command following the macro code for
// a typical example of the command's syntax.]
// Hence, if the macro is played "as is," any of the keys pressed
// will simply display a message and exit. So you must insert valid
// macro commands that perform some action(s) following
// (i.e., to the right of) each of the first 6 CaseOf() commands ... and
// any similar CaseOf() commands you use for other alphanumeric keys.

// Note also 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"): Messagebox(;;"You pressed the '0' key")
CaseOf ("1"): Messagebox(;;"You pressed the '1' key")
CaseOf ("2"): Messagebox(;;"You pressed the '2' key")
CaseOf ("a"): Messagebox(;;"You pressed the 'a' key")
CaseOf ("b"): Messagebox(;;"You pressed the 'b' key")
CaseOf ("c"): Messagebox(;;"You pressed the 'c' key")
// ... etc.

// Other keys that might be pressed when the macro plays:
// (if NOT used to do something, optionally retain their Messages
// to inform the user; otherwise there won't be any feedback with them)
CaseOf ("33062"): Messagebox(;;"You pressed the Backspace key")
CaseOf ("33051"): Messagebox(;;"You pressed the Delete key")
CaseOf ("33177"): Messagebox(;;"You pressed the Enter key")
CaseOf ("33040"): Messagebox(;;"You pressed the Ctrl+Enter key")

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

Default: vKey:=?Pausekey

MessageBox(; "No key assigned";
"The 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 document to be closed without saving it (i.e., it would "quit"). [Old timers might remember WordStar: This was one of WordStar's commands to quit the document.]


  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 dialog-less macro in Sample #1 above.]

2-keys macro dialog

Note on the macro code below

•  The accented letters used in the CaseOf commands shown in the example below were entered using the numeric keypad (see next paragraph). They can also be selected and copied from the Windows Character Map on your system, then pasted into the relevant Type() command between the double quote marks.

    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. (You can use Start, Programs, Accessories, System Tools, Character Map -or- in more recent versions of Windows, use the Windows search field and search for "Character Map"). For some items it can be easier to use the select-copy-paste method directly from the Character Map.

Tips

•  To copy this macro code into your WordPerfect to produce a functioning macro, see here.

•  You can make copies of the macro's code below to use as separate macros. For example, instead of the grave accent (`) marks, use acute accent (´) or umlaut (two dot) marks. Save and compile the macros and then assign each macro to separate shortcut keys (instructions here) — using keys that are available and (preferably) easy for you to remember. For example, you could assign the grave accent mark macro to the Alt+` key (next to the "1" key); assign the acute accent mark macro to the Alt+' (single quote) key; and assign the umlaut mark macro to the Alt+u key.

// Macro code begins here

OnCancel(End@)
OnError(End@)

// Pop up a small dialog with the Char() command:
Char (vNextChar; "Enter a lower- or uppercase letter: ")

vKey:=NToC(vNextChar) // (used in Messagebox)

Switch(NToC(vNextChar))

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

Default:  MessageBox(; "No key assigned"; "The 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 code ends here

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

Tips and alternatives for inserting accented characters

Some users might be aware of the SendKeys() macro command. However, with Windows Vista and later Windows versions that macro command — 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 (or by copying them from the Windows Character Map) 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:

•  EZMenu is a macro s an example of a simple menu using the Menu() command and some simple Switch() statements containing various macro commands.

•  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 [scroll down on that page]."

•  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. [Search the Internet for "US international keyboard in Windows 10" or similar.] 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").

•  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 alongside WordPerfect's QuickCorrect).


  Sample macro 3

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 toolbar button is pushed (i.e., the second keystroke) on the pop up dialog.

Push button macro to change case of text

[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.) [You can also assign the macro to a toolbar button if you prefer using a mouse.]

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 code into your WordPerfect to produce a functioning macro, see here.

// Macro code 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;"&Quit")
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
CaseOF 104: Go (EndItNow@)
Endswitch

// Exit here:
Label(EndItNow@)

// Tip: If you want to de-select the item after it is processed
// remove the leading slash marks from this SelectOff command:
//SelectOff

Return

// Macro code ends here

Tip

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


  Sample macro 4

Here is a two-keystroke macro to insert a chosen letter's closing ("signature block") at the current cursor location.

For example:

Sample macro menu for letter closings

Clicking a button or pressing the letter (underlined) instantly inserts this at the cursor location:

Sincerely yours,


________________________________
Susan Doe

Notice that it adds a horizontal graphics line above the person's name to underline their inked signature. (See the Tip below the macro code about using an image of the actual signature with the inserted text.)

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

Tip: Assign the macro to a key and then, when the menu appears, press the letter (preceded by a & character in the code below) to insert the name, or just press "a" to abort. [You can also assign the macro to a toolbar button if you prefer using a mouse.]

To copy this macro code into your WordPerfect to produce a functioning macro, see here.

// Macro code 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!;"&Quit")

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 code ends here

Tip

A graphic image could be included in each signature block, such as an image of the actual signature (see "Adding my signature to a document" at WordPerfect Universe here).

    This might be best accomplished by using a QuickWord to insert and expand each appropriate (entire) signature block (text, spacing, and image).

    For such a macro you would delete the lines from "// Start the closing...." up to "//Insert the name" and then use just AbbreviationExpand(<QuickWord-name-here>) in each CaseOf section of the Switch() command instead of the Type() commands used in the example.


  Sample macro 5

This "push button" macro is by Roy ("lemoto") Lewis's macro on WordPerfect Universe at http://www.wpuniverse.com/vb/showthread.php?postid=40594#post40594. [Ed.- Code is slightly modified to adjust dialog width and button widths.]

See also Sample macros #3 and #4 for simpler push-button macros —  i.e., without Callback routines. They might be easier to modify by those without macro writing or editing experience.

Sample push button macro to select a task

When a button is pushed 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 in the code below (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 code into your WordPerfect to produce a functioning macro, see here.

// Macro code begins here

vDoIt=""


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

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

// Macro code ends here

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.


  Additional sample macros


See Footnotes below.

[Page Top]


Footnote 1
[Referenced in Sample #4 above...]

Note

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

Explanation

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.

Tip

UPDATE: For WordPerfect X9 (released in 2018) and later versions you can use Edit, Convert Case, Lower case since now it will convert ALL characters in your selection of text to lower case. But the methods below might still be useful (adapted to your needs) when you want to "step" thought a large block of text, a character at a time.

[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 [no menu]

Important

This macro uses a Greek omega "Ω" character (the same as WordPerfect symbol 8,50) where indicated below. This character is used as a "terminator" to tell the macro when to stop processing.

You can use any character symbol that is not used elsewhere in the document. (If it comes from the WordPerfect symbol sets (Ctrl + w) be sure to enclose it in double quote marks since WP symbols are characters.) The omega character, converted from its numerical value with the macro command NToC, 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 code into your WordPerfect, see here.]
// Macro code begins here:

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


// First, verify the document is not empty:
If(?DocBlank)
    MessageBox(;"Current Document is Blank";
    "This macro requires text that can be processed.";IconStop!)
    Quit
EndIf

// If nothing is currently 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(NToC(2098)
) // <= NToC(2098) equals an "Ω"
BookmarkBlock("TempMarker")
PosBlockTop
SelectOff
BookmarkDelete("TempMarker")


// Step through the selection:
While(?RightChar<>NToC(2098)
) // <= NToC(2098) equals an "Ω"
// 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 code ends here

  Sample macro 7 [no menu]

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.

[To copy this macro code into your WordPerfect, see here.]
// Macro code begins here:

Display(Off!)
// First, verify the document is not empty:
If(?DocBlank)
    MessageBox(;"Current Document is Blank";
    "This macro requires text that can be processed.";IconStop!)
    Quit
EndIf
// 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 code ends here
[Page Top]


Footnote 2
[...Continued from above:]

  Sample macro 8

Here is a demonstration macro using a push button menu that uses 36 buttons to represent the keyboard's a-z keys and the 1-0 keys.

36 choice menu

Note that this macro simply displays a confirmation message when any of the 36 keys are pressed -- otherwise it does nothing useful. It is a demonstration macro to help you with the macro's structure and command syntax.

However, you can replace the various Messagebox() commands in the macro code below with appropriate commands for your tasks.

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

// Macro code begins here

// Purpose: Demonstrate a pop up menu with multiple push buttons (a-z; 1-0). The buttons can be activated with a key press or with a mouse click, and the menu then immediately disappears, replaced by a confirmation Message.

OnCancel(EndIt@)
vTitle:="--DEMO--> 36 choice menu"
vTxt1:="Please type (or click on) a letter or number:"
vTxt2:="( or press Esc or Alt + F4 )"

// Display a "push button" menu:
DialogDefine ("Menu";50;50;230;110;Percent!;vTitle)
DialogSetProperties ("Menu";FontName:"Arial")
DialogAddText ("Menu";"Txt1";5;5;240;14;Left!;vTxt1)

// Add buttons in 3 rows on the dialog:

DialogAddPushButton ("Menu";101;15;20;12;14;0;"&a")
DialogAddPushButton ("Menu";102;30;20;12;14;0;"&b")
DialogAddPushButton ("Menu";103;45;20;12;14;0;"&c")
DialogAddPushButton ("Menu";104;60;20;12;14;0;"&d")
DialogAddPushButton ("Menu";105;75;20;12;14;0;"&e")
DialogAddPushButton ("Menu";106;90;20;12;14;0;"&f")
DialogAddPushButton ("Menu";107;105;20;12;14;0;"&g")
DialogAddPushButton ("Menu";108;120;20;12;14;0;"&h")
DialogAddPushButton ("Menu";109;135;20;12;14;0;"&i")
DialogAddPushButton ("Menu";110;150;20;12;14;0;"&j")
DialogAddPushButton ("Menu";111;165;20;12;14;0;"&k")
DialogAddPushButton ("Menu";112;180;20;12;14;0;"&l")
DialogAddPushButton ("Menu";113;195;20;12;14;0;"&m")

DialogAddPushButton ("Menu";114;15;40;12;14;0;"&n")
DialogAddPushButton ("Menu";115;30;40;12;14;0;"&o")
DialogAddPushButton ("Menu";116;45;40;12;14;0;"&p")
DialogAddPushButton ("Menu";117;60;40;12;14;0;"&q")
DialogAddPushButton ("Menu";118;75;40;12;14;0;"&r")
DialogAddPushButton ("Menu";119;90;40;12;14;0;"&s")
DialogAddPushButton ("Menu";120;105;40;12;14;0;"&t")
DialogAddPushButton ("Menu";121;120;40;12;14;0;"&u")
DialogAddPushButton ("Menu";122;135;40;12;14;0;"&v")
DialogAddPushButton ("Menu";123;150;40;12;14;0;"&w")
DialogAddPushButton ("Menu";124;165;40;12;14;0;"&x")
DialogAddPushButton ("Menu";125;180;40;12;14;0;"&y")
DialogAddPushButton ("Menu";126;195;40;12;14;0;"&z")

DialogAddPushButton ("Menu";127;15;60;12;14;0;"&1")
DialogAddPushButton ("Menu";128;30;60;12;14;0;"&2")
DialogAddPushButton ("Menu";129;45;60;12;14;0;"&3")
DialogAddPushButton ("Menu";130;60;60;12;14;0;"&4")
DialogAddPushButton ("Menu";131;75;60;12;14;0;"&5")
DialogAddPushButton ("Menu";132;90;60;12;14;0;"&6")
DialogAddPushButton ("Menu";133;105;60;12;14;0;"&7")
DialogAddPushButton ("Menu";134;120;60;12;14;0;"&8")
DialogAddPushButton ("Menu";135;135;60;12;14;0;"&9")
DialogAddPushButton ("Menu";136;150;60;12;14;0;"&0")

// Tip:
// The next
DialogAddPushButton() command creates an "active" Cancel button on the menu -- i.e., when the Enter key is pushed the macro is canceled because the button is marked as a default button.
// To make it "passive" -- i.e., where you must deliberately click on that menu button with your mouse (alternative: press the Esc or Alt+F4 key) to cancel the macro -- remove both the "DefaultBttn!" and the "|" from the command's parameter.

DialogAddPushButton
  ("Menu";199;90;90;40;14; DefaultBttn! | CancelBttn!;"Cancel")

DialogAddText ("Menu";"Txt2";135;93;90;14;Left!;vTxt2)
DialogShow ("Menu";"WordPerfect";199)
// Store the menu choice and use it in the Switch command:
vAns:=MacroDialogResult

Switch(vAns)

CaseOF 101: Messagebox(;;"You chose button [ a ]")
CaseOF 102: Messagebox(;;"You chose button [ b ]")
CaseOF 103: Messagebox(;;"You chose button [ c ]")
CaseOF 104: Messagebox(;;"You chose button [ d ]")
CaseOF 105: Messagebox(;;"You chose button [ e ]")
CaseOF 106: Messagebox(;;"You chose button [ f ]")
CaseOF 107: Messagebox(;;"You chose button [ g ]")
CaseOF 108: Messagebox(;;"You chose button [ h ]")
CaseOF 109: Messagebox(;;"You chose button [ i ]")
CaseOF 110: Messagebox(;;"You chose button [ j ]")
CaseOF 111: Messagebox(;;"You chose button [ k ]")
CaseOF 112: Messagebox(;;"You chose button [ l ]")
CaseOF 113: Messagebox(;;"You chose button [ m ]")

CaseOF 114: Messagebox(;;"You chose button [ n ]")
CaseOF 115: Messagebox(;;"You chose button [ o ]")
CaseOF 116: Messagebox(;;"You chose button [ p ]")
CaseOF 117: Messagebox(;;"You chose button [ q ]")
CaseOF 118: Messagebox(;;"You chose button [ r ]")
CaseOF 119: Messagebox(;;"You chose button [ s ]")
CaseOF 120: Messagebox(;;"You chose button [ t ]")
CaseOF 121: Messagebox(;;"You chose button [ u ]")
CaseOF 122: Messagebox(;;"You chose button [ v ]")
CaseOF 123: Messagebox(;;"You chose button [ w ]")
CaseOF 124: Messagebox(;;"You chose button [ x ]")
CaseOF 125: Messagebox(;;"You chose button [ y ]")
CaseOF 126: Messagebox(;;"You chose button [ z ]")

CaseOF 127: Messagebox(;;"You chose button [ 1 ]")
CaseOF 128: Messagebox(;;"You chose button [ 2 ]")
CaseOF 129: Messagebox(;;"You chose button [ 3 ]")
CaseOF 130: Messagebox(;;"You chose button [ 4 ]")
CaseOF 131: Messagebox(;;"You chose button [ 5 ]")
CaseOF 132: Messagebox(;;"You chose button [ 6 ]")
CaseOF 133: Messagebox(;;"You chose button [ 7 ]")
CaseOF 134: Messagebox(;;"You chose button [ 8 ]")
CaseOF 135: Messagebox(;;"You chose button [ 9 ]")
CaseOF 136: Messagebox(;;"You chose button [ 0 ]")

Endswitch

// Exit here:
Label(EndIt@)
Return

// Macro code ends here


[Page Top]