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

Page updated Mar 29, 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 e-mail messages or BBS/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 similar macro by Ron Hirsch but one that can also add more than a single attribute to an existing one in one operation, and it can even remove (delete) the underlying material to which a chosen attribute was applied (but there are some cautions, as noted on that download page).


Replace Codes.wcm (v1.02, updated May 7, 2019) is a macro that can quickly search for a user-chosen text attribute (the responsible format codes are visible in Reveal Codes) and then changes it to something else.

For example, you can instantly change -

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

When you play the macro it displays a menu -

Replace Codes menu

where you can  -

•  pick one of 16 attributes to search and replace;
•  start all processing at the top of the document -or- at the current cursor location;
•  search in all areas or just in the body text area;
•  replace a chosen attribute with a different attribute or with a style;
•  add an attribute to the existing attribute (e.g., add bold to redlined text);
•  remove just the chosen attribute codes to return the item to normal text;
•  pause at each item found to allow you to examine it and -
confirm each change,
skip that item,
process all remaining items automatically, or
cancel the macro at that point.

The attributes* (actually, their paired format codes) that you can search for and change are -

Double Underline
Small Caps
Very Large
Extra Large
* The first 16 attributes are the same ones available to apply to text from a drop down list located on the program's Text property barProperty bar text attribute button
** Highlighting acts like text attributes in that it applies a pair of On/Off codes to the document text. But there's something to keep in mind when removing highlighting: See Footnote 1 below.

*** A character style or paragraph style can be used as a replacement for the chosen text attribute. This 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.


Note that the macro option to remove your chosen attribute does not delete the underlying material to which the attribute was applied.


☼  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.

☼  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.
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.

Format codes inside the aforementioned "container-like" codes need to be edited/changed from inside those container codes. Double-click on those codes in the Reveal Codes window to examine and edit them.

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 here.

Finally, because this macro uses drop lists, radio buttons and a checkbox 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 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.