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

Page updated Aug 18, 2020

Replace Codes - Quickly change text attributes (e.g., bold, underline, italics, large size, etc.) by replacing, adding, or deleting a chosen attribute wherever it appears in the current document

Download REPLACECODES.ZIP (v1.02; 05/07/19; 33,897 bytes)

Written in WordPerfect X9 but should be compatible with other versions

WordPerfect 11 users: See important information about using macros in the first release of WP11 ( at the top of this page.

Downloading, Documentation, Modifications, and Support

Related pages -

•  AddCodes - A macro that can quickly search the current document for up to 10 specified words or phrases and, when found, add one or more text attributes (e.g., Bold, Underline, Italics, Redline, Large size, etc.) to them wherever they appear in that document.

  Code2txt -  A macro that can change text surrounded by WordPerfect format codes (e.g., [Bold On]...[Bold Off]) to text surrounded by user-defined plain-text markers (e.g., <B>...</B>) -- and vice versa.

•  DelCodes - a small suite of three macros to quickly delete one or more attribute codes of various types -- including many types not processed by the Replace Codes macro.

•  HiLite - A suite of macros for annotating or marking up drafts or other documents using highlighting; includes a macro (HiLiteDoc) that can highlight specific words in a document [and another to remove all (or just some) highlighting from a document with an option to remove the underlying highlighted text].

•  LineWrap - A macro to remove hard returns ([HRt]) at the end of lines in plain-text (ASCII-type) files that have been imported into WordPerfect, and replace them with soft returns ([SRt]). This allows "word wrapping" of sentences and paragraphs and makes reformatting such paragraphs or other copied material (such as email messages or internet downloads) much easier.

•  ReplStyl - A macro that can replace one built-in (system) or custom (user-created) style with another in a document, or remove a style's codes to remove the style wherever it was applied in the document.

•  Replace Codes - Plus, a macro by Ron Hirsch that is similar to Replace Codes but one that can also add more than a single attribute to an existing one in a single operation, and it can even remove (delete) the underlying material to which a chosen attribute was applied. (But there are some cautions, noted on that download page.)

Copyright, Modification, and Distribution of Materials, and
Privacy Policy


Replace Codes.wcm is a macro that can quickly search for a user-chosen text attribute (its format codes will be visible in Reveal Codes) and then replaces it with another attribute (or style), or optionally removes it from the text to which it was applied.

For example, you can instantly change any or all 

•  underlined text to italic text
•  redlined text to bold redlined text or strikeout text
•  bold text back to normal text (i.e., not bolded)
•  large relative size text to highlighted text or vice versa
•  redlined text to a custom style (perhaps also containing redline)
•  ... etc.


1.  Once the macro is saved in your Default or Supplemental macro folder (see the "Downloading..." page if you need help with this), simply play the macro (Tools, Macro, Play -or- press Alt+F10).

It displays a dialog menu with 2 drop-list buttons and several choices:

Replace Codes menu

On the left side of the dialog:

2.  Choose the desired text attribute to search from the first drop list (#1).

3.  Set an option to -

•  search for that attribute starting at the top of the document
•  search starting at the current cursor location
  either search all areas (tick the box) or search just the main text area in the document (clear the box).

On the right side of the dialog:

4.  Choose one of the replacement attributes from the second drop list (#2).  (When using that drop list you can also tell the macro to use an existing WordPerfect style as the replacement (see more below).)

5.  Set an option to -

•  replace it with an attribute chosen from the second drop list  (or even replace it with an existing style)
•  add the second attribute to the first attribute (e.g., add bold to redlined text)
•  remove just the first attribute's codes (e.g., to return the item to normal text, or remove bold codes from bold underlined items; etc.)
■  either pause at each item found (tick the PAUSE box) to allow you to examine it so that you can -

confirm each change, or
skip that item, or
process all remaining items automatically, or
cancel the macro operation at that point.

Clear the PAUSE box to prevent pausing the macro. The macro will then process the entire document without pausing.

6.  Click OK.

Note:  The macro option to REMOVE the attribute chosen in drop list #1 does not delete the underlying document material to which that attribute was applied.

• • •

  The text attributes* (actually, their paired format codes) that are shown in the drop lists are ...

Double Underline
Small Caps
Very Large
Extra Large
<style> (replacements only)

* The first 16 attributes (Bold...Extra Large) are the same ones available to apply to text from a drop down button located on the program's Text property bar: Property bar text attribute button
[Note that S̶t̶r̶i̶k̶e̶o̶u̶t̶  and Redline text attributes are not the same thing as deletions and insertions created with File, Document, Compare/Review even though they may look the same on screen. See the tip below.]

** Highlighting acts like text attributes in that it applies a pair of On/Off codes to the document text. But depending on your WordPerfect version there's something you might need to keep in mind when removing highlighting: See Footnote 1 below.

*** An existing character style or a paragraph style can be used as a replacement for the chosen text attribute since these are also created with paired format codes. (Document styles are "open," consisting of a single code, so they cannot be used to replace the paired codes used for the first 17 attributes above.)

The <style> replacement option (using the style specified on the second screen of the macro's menu) is especially useful if you have created a custom style since it would give you a handy "container" to include several attributes and other desired formatting, such as a different font — and any of these items can be instantly changed wherever the style was applied. Simply edit any one of the [Style] codes in the document by double-clicking on that code. Such quick, global changes can be very useful for future editing tasks.

  Be sure to read the following material before playing this macro.


☼  Always make a backup of your document before playing this (or any) macro.

☼  This macro's menu choices can be set to your preferred defaults in the redlined User Modification Area at the top of the macro's main code section. Open the macro like any other WordPerfect document, make the change(s) in that area, click the Save & Compile button on the toolbar just above the edit screen area.

☼  Since this macro searches just one attribute at a time, you will need to play it again to replace/add/remove a different attribute. Be aware that sometimes more than one attribute have been applied to the same text (e.g., Bold+Italics), and sometimes they were applied to different text (e.g., just Bold applied to some words, and just Italics to other words), so it's a good idea to use the macro's "Pause to confirm" option to let you see each item found and choose whether to process it or skip it.

☼  If you want to quickly delete one or more attribute codes of various types see the DelCodes three-macro suite. The DelCodes.wcm macro in that suite includes a much wider selection of format codes than are processed by this macro. It can help fix problematic formatting when you suspect a code — or several codes — should be removed so you can "start over". However, unlike Replace Codes it does not offer an option to pause for confirmation at each item found (hence, always make a back up first).

☼  The S̶t̶r̶i̶k̶e̶o̶u̶t̶  and Redline attributes are NOT the same thing as deletions and insertions created with File, Document, Compare/Review even though they may look the same on screen. The latter feature (not available in some editions/versions of WordPerfect) produces deletions and insertions using special codes that work differently from font attributes. Hence those codes are not processed by the Replace Codes macro. See (e.g.) "Using Document Compare" and WordPerfect's Help (F1) for more.

Known limitations

As discussed on the Toolbox page about WordPerfect's Find and Replace feature, searching for a format code inside another code, such as a ...

Style code (including the initial Open Style code in a document),
text variable, or a
Delay Code

... is not curretnly possible in WordPerfect
without (possibly) a great deal of extra coding. This is a limitation of the program, not of this macro. (It even exists in the program's Edit, Find and Replace feature.)

Hence this macro can only process text attribute codes that are directly visible in Reveal Codes when your cursor is in the various document areas.

Format codes inside the aforementioned "container-like" codes need to be edited/changed from inside those container codes. You can double-click directly on those codes in the Reveal Codes window to examine and edit their contents.

Note for macro writers

Many macros on the wptoolbox.com site have pop-up menus or messages created with the program's built-in Dialog Editor. This macro, however, uses the legacy "hard code" written command method. These commands begin just below the User Modification Area.

Further, in SearchString() commands, where typically a search for attribute codes requires pasting the macro function equivalents (i.e., binary codes) from the Macro Toolbar's Codes button into the SearchString() parameter, surrounded by double quote marks, this macro uses NToC() equivalents for those WordPerfect binary codes.

Using NToC() values was done to work around the problem of posting "raw" macro code on a website or sending it via email, which strips out any WordPerfect binary codes.

A full list of these equivalent codes is available in a PDF file on the Toolbox site here.

Finally, because this macro uses drop lists, radio buttons and checkboxes for the menu — three common features on macro menus — the written command ("hard-code") method might be helpful when writing your own macros that require a menu using one or more such menu features.

Footnote 1

[...Continued from above:]

Something to keep in mind when applying highlighting in WordPerfect X4 (released in 2008) and later versions

In these WordPerfect versions, if you use Tools, Redaction during draft document creation, Redaction codes ([Redact:Mark]) will be inserted in the document.

These appear to act like (gray) highlighting and they might be removed if highlighting is applied or if [Highlight] codes are removed globally by the macro.

Be careful when applying (or removing) highlighting in such a document. You don't want to accidentally remove "markers" for text that should be redacted. It is better to convert the document to a redacted version first, whereupon the Redaction codes will have done their job. For more information about this issue and some macro code snippets, see this PDF document.


☼  The default highlight color (bright yellow) used by the macro when adding highlighting is coded into the macro with the command -

HighlightColor (Red: 255; Green: 255; Blue: 0; Shade: 100)

If you remove or comment out this command ("//"), you'll be able to preselect any highlight color before playing the macro.

In the same vein, you can set some other default color for the macro to use by changing the command's parameters (color values can be 0-255; shade values are 0-100).

☼  To replace one highlight color with another color wherever it occurs, simply play the macro and replace all existing highlighting in the document with something you aren't using in that document, such as the Shadow text attribute.

Then set the new highlight color on the toolbar and play the macro again, replacing all Shadow attributes with highlighting.

Or, you could use HILITERC (included in HILITE.ZIP) to change the color of existing highlighting in a document.