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

Page updated Sep 27, 2017

WordPerfect Tips
Main tips page | Browse more tips

Enhancing the Find and Replace feature

Find and Replace dialog

Related pages -

How to efficiently use "Find:" in the Find and Replace (F&R) dialog

REPLACEM - Replace multiple words in one pass (with macros)

DELCODES - Delete one or more types of format codes from a document in one pass

Often, the standard Find and Replace dialog has to be dragged from its position in the center of the screen if you want to see the item found or the item to be replaced.

Moreover, it does not provide an easy way to replace (or format) just certain instances of an item.

Finally, having to repeatedly open the F&R dialog (Edit, Find and Replace, or <Ctrl+F>) to find or replace the same item is tedious.

Here's a tip posted by Pam Britt on WordPerfect Universe that may help:

"To repeat a find once you have closed the dialog box, you need not reopen the box. Simply press <Ctrl+Shift+F> . . . to go to the next occurrence of your designated find text.

[Editor's note: If you use the DOS keyboard instead of the standard Windows keyboard, you will need to assign the "Find and Replace" and "Find Next" features to <Ctrl+F> and <Ctrl+Shift+F>. See the tip about assigning a macro, feature, program, or string of keystrokes to a key or key combination (i.e., a "shortcut" or "hot key"), here.]

This is an extremely efficient tool for the kind of templates I have prepared over the years and through many versions of WP, placing # symbols where I would eventually need to add text and @ symbols where others would need to do so. These and other symbols can be searched to easily and then replaced on the run. (The "find" highlights the character [but see below], and all you have to do is start typing the new text -- no <Escape>, no <Delete>, no nothing. If text (or a symbol) is highlighted and you need to change it, start typing; if you need to go to the next instance, just press <control>+<shift>+f again.)

It is also very simple to replace text using this feature. All that's needed is for you to have already marked for copying [i.e., copied to the clipboard with <Ctrl+C>] the "replace with" text; then, when you hit on an instance where you need the text replaced, paste the "replace with" text over the found text [with <Ctrl+V>]...."

However, sometimes there is a problem with the part of Pam's tip that says -

...The "find" highlights the character, and all you have to do is start typing the new text...

Most of the time this will be true. But if the user has set Edit, Find and Replace, Action to "Position Before" or "Position After," or plays a macro that sets the Action to these values, then the items found will not be selected (i.e., "highlighted"). These items on the Action menu in Find and Replace are "sticky," so their settings will persist into the next session.

Here's a solution:

Create and play the Find and Replace.wcm macro below, which could be assigned to the <Ctrl+F> and/or <F2> key instead of simply the "Find and Replace" feature. It will reset the Find and Replace dialog's settings first; then it will pop up the Find and Replace dialog. This will be completely transparent to the user.


▸  To copy the macro code below into your own WordPerfect and create a functioning macro, see here

▸  For help assigning macros to keystroke combinations ("shortcut keys") see here.


The two code snippets below in blue (by Klaus Pfeiffer at WordPerfect Universe) allow displaying the Find and Replace dialog at the top of the WordPerfect window to maximize visibility of the main text area. [Screen shot of dialog] You can adjust the horizontal offset from the center and the vertical offset from the top of the main WordPerfect window, in the SetWindowMostTop() command (i.e., the two numbers shown in bright red).

Note also that the AppLocate() command must have the exact name of your Find and Replace dialog (the macro assumes English editions of WordPerfect).

The two snippets in blue are optional, and can be deleted if desired. (The FindDlg() command is required if you want to display the F&R dialog.) The macro then will simply reset Find and Replace settings to factory defaults (using the Procedure) when it displays the F&R dialog.

Some Find and Replace dialog settings -- such as the Option to specify a Search inside headers, footers, footnotes, endnotes, text boxes, and other "substructures" -- are not amenable to being reset by a macro (no relevant commands exist). Hence, you should manually check the F&R dialog's menu and enable (or disable, as your needs dictate) the Option to "Include Headers...".  However, in writing macros, search and replace command parameters (Regular! and Extended!) can be used to set (and reset) the type of search or replace operation, as needed.

// Find and Replace.wcm

// Purpose: Enhances the use of the standard Find and Replace feature by ensuring that certain WordPerfect default settings for the F&R dialog are reset -- especially the "Select Match" option in the Action menu, which normally leaves the item selected (and thus more visible on screen) after it is found.

// Important Note:

// This macro sets various other options for the standard Find and Replace feature in the Procedure at the end of the macro code -- such as some settings that might have been used during the session that you might want to have enabled (or disabled).

// For example, if you want to search inside selected material the Procedure below automatically disables "Limit Find Within Selection" by using the SearchInSelection (No!) command. Use Yes! in that command's parameter to search only in the selection.

// Tip:

// For convenience you can assign this macro to the <Ctrl+F> key and/or <F2> key to replace the standard methods of bringing up the Find and Replace dialog.

// Main macro code begins here:

  Messagebox(;"Error";"Document is blank.";IconInformation!)

OnCancel (End@)
pResetFindReplace ()

// Open the Find and Replace dialog at the top
// of the screen (these
two snippets by Klaus Pfeiffer):

DllCall Prototype SetWindowMostTop ("User32"; "SetWindowPos"; dword!;
{dword(h); dword(h2); dword(x); dword(y); dword(cx); dword(cy); dword(f)})


hFind = AppLocate("Find and Replace")
// API DLL call to make dialog stay on top of everything (-1)
// Move the dialog 500 units to the right, 10 units down
SetWindowMostTop(hFind; -1;
500; 10; 0; 0; 1)

// Exit from the macro:
Label (End@)

Procedure pResetFindReplace ()
SearchString ("")
ReplaceString ("")
// Only one of these next 4 Match... commands can
// be active at any one time:
// MatchPositionAfter ()
// MatchExtendSelection()
// MatchPositionBefore()
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!)

// End of macro

When the found item is shown selected on screen you can use other standard formatting shortcut keys to quickly make the instance bold, italic, underlined etc. Just press <Ctrl+B> for bold, <Ctrl+I> for italic, etc., while the item is selected. Then simply press <Ctrl+Shft+F> to go to the next instance of the item, if desired.

You might even like to highlight the found-and-selected item (or any selected words) in the current highlight color. 

[Alternative: If you want a macro that can highlight one or more words in any of several different highlight colors without using the F&R dialog, see HiLiteDoc here.] 

Since there doesn't seem to be a built-in feature in WP's keyboard editor that you can directly assign to a shortcut key for this, use a macro instead. You can assign the small macro below to, for example, the <Ctrl+H> key to toggle highlighting on for the selected item.


To copy this macro into your own WordPerfect see here

For help assigning macros to keystroke combinations ("shortcut keys") see here.


If you use the Redaction Tool in the initial release of WordPerfect X4, here are some tips (click here for the PDF version) when using normal highlighting (Tools, Highlight) in the same document that is marked up for redaction (Tools, Redaction).

// Highlight Toggle.wcm - Toggle selected text to highlighted text.
// Assign to <Ctrl+H> or similar key for convenience.

 Messagebox(;"Highlight Toggle";"Select some text first!";IconWarning!)

Finally, note that redline or strikeout formatting (not to be confused with similar effects produced during a file Compare or Review) are not assigned to any standard shortcut key. However, they can be assigned to one using the "Attribute Redline" and "Attribute Strikeout" choices in the Format feature list, found in the keyboard editor's Keyboard Shortcuts window. Assigning them to <Alt+Ctrl+R> and <Alt+Ctrl+S> or other preferred keys might be handy. Since they do not require that the item be selected first, no macro such as Highlight Toggle above is needed.