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

Page updated Jul 31, 2018

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

Download REPLACECODES.ZIP (v1.0; 07/30/18; 20,261 bytes)

Written in WordPerfect X9 and should be compatible with other versions

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

Downloading, Documentation, Modifications, and Support


Related pages -

•  Replace Codes - Plus, a more flexible macro that can also process highlighting codes, add more than a single attribute to an existing one, convert found items into a custom style, process just the main body text or all text areas, and optionally just remove a chosen code. It can even remove (delete) the underlying material to which a chosen attribute was applied.

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




Overview

Replace Codes.wcm - A macro that can search for a menu-chosen text attribute wherever found in the document and then change it to something else.

[This macro is a "lite" version of the similar maco, Replace Codes - Plus. See the left sidebar under "Related pages".]

For example, with this macro you can instantly change -

•  underlined text to italic text
•  redlined text to bold redlined text or strikeout text
•  bold text back to normal text
(...etc.)

When you play the macro it displays a menu [screen shot] where you can  -

•  pick one of 16 attributes to search and replace;
•  start all processing at the top of the document at the current cursor location;

•  replace a chosen attribute with a different attribute;
•  add an attribute to the existing attribute (e.g., add a relative large size 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 remaining items automatically, or simply cancel the macro at that point.

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

Bold
Italic
Underline
Double Underline
Strikeout
Redline
Outline
Shadow
Small Caps
Subscript
Superscript
Fine
Small
Large
Very Large
Extra Large

These are the same choices available to apply to text from a drop down button on the program's Text property bar:  Property bar text attribute button
Note that the macro option to remove your chosen codes does not delete the underlying material to which the attributes were applied. (See the Tips below for a macro that can do this.)

Tips

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

•  For a more flexible macro see Replace Codes - Plus. It can also process highlighting codes, add more than a single attribute to an existing one, convert found items into a custom style, process just the main body text or all text areas, and optionally just remove a chosen code. It can even remove (delete) the underlying material to which a chosen attribute was applied.

•  If you want to quickly delete one or more attribute codes of various types see the DelCodes three-macro suite. It includes a wider selection of format codes than are processed by this macro.

• NOTE: The Strikeout and Redline font 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.

Hence this macro can only process 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 NToC() 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.