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

Page updated Oct 25, 2023

CODE2TXT - Change attribute codes to text markers (and vice versa)

Download CODE2TXT.ZIP (versions 2.14 and 2.0; 02/02/10; 64,932 bytes; contains two macros and a README file)

Compatible with WordPerfect 8 and later versions (version 2.14 is for WP9 and later versions; version 2.0 is for WP8)

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 item

The Code2Txt macro on this page can change paired WordPerfect format codes to text markers or vice versa.

However ...
To replace (or augment) one or more existing paired format codes with one or more different paired format codes, see the ReplaceCodes macro in the Library here.



The download file CODE2TXT.ZIP contains two macros.

Both macros are named -
    Change attribute codes to text markers.wcm

- but there are different version numbers in their filenames.

For WordPerfect 9 and later use the one with the higher version number. (See Download box at left.)


This macro (Change attribute codes to text markers.wcm) can -

•  change text bracketed by pairs of WordPerfect format codes (e.g., [Bold On]...[Bold Off]) to the same text bracketed by pairs of user-defined plain-text markers (e.g., <B>...</B>)

or do the opposite - 

•  change text bracketed by pairs of user-defined text markers (e.g., <B>...</B>) to the same text bracketed by pairs of WordPerfect format codes (e.g., [Bold On]...[Bold Off]).

The first function (convert format codes to text markers) is useful when converting (saving) a document to ASCII or ANSI text but you want to identify the old text attributes (i.e., paired format codes) with unique text markers, such as HTML tags or to replace WordPerfect format codes with Folio, Ventura Publisher, InDesign, or QuarkXpress markup codes, etc.

The second function (convert text markers to format codes) can be useful to restore a document saved after converting from codes to text markers with the first function, or whenever you want to convert identical, "marked" strings of text to formatted text (e.g., bold, redline, etc.). Note that you can also use it to convert text "marked" with ordinary words (up to 20 characters) and/or symbols (inserted with <Ctrl+W>).

The WordPerfect attribute codes that can be converted (in v2.13+) are:

Double Underline
Small caps
Very Large
Extra Large
Highlight *

You can choose any — or all
of these codes to convert from a menu.

You can use the sample text markers provided — or use your own markers. (Be sure to read the instructions below.)

You can also choose to retain the original paired format codes after converting the codes/markers **, and/or delete all 'empty' code pairs (i.e., a pair of on/off codes without anything between them, such as [Bold][Bold]).

You might notice that some format codes such as [Color] are not listed. That is because they are not paired codes, even though they can be turned off later in the document with a corresponding code of the same type (in this example, a different [Color] code). On the other hand, the text attribute codes above are paired codes consisting of an "on" code and an "off" code.

Perhaps the best way to see what the macro does is to play it on a test document that contains typical paired format codes such as bold, italics, and/or underlines (or any combination), using the first option on the macro's menu. These codes should be converted to the text markers you have chosen.

* Please be aware that changing highlighting codes to text markers (such as <H> and </H>) changes all instances of highlighting regardless of the highlight's color, and changing text markers back to highlighting uses the current highlight color — i.e., the one chosen on the main toolbar (or with Tools, Highlight, Color). This is a limitation of the program's macro language, not the macro itself.
On the "Change format attribute..." menus that appear [screen shot], enabling the option "Retain original attributes after marking text..." (which is disabled by default) can be useful while working on the document: It may be easier to see areas to which the attribute was applied along with their new text markers. When you save the document in ASCII or ANSI format the new text markers will be retained but all existing format attributes will be discarded. (Tip: You can always delete any or all specific attribute codes anytime a document is open with the ReplaceCodes macro.)


Download and extract the desired macro using the link in the left sidebar.
Place the extracted macro in your Default or Supplemental macro folder.
(See "Downloading..." for more help if you need it.)

Be sure to read the rest of this page before using the macro.

Then -

[1] Back up your document.

[2] Play the macro.

[3] An initial menu will appear [screen shot] to let you choose from the two basic options. Choose one of them and click OK.

[4] A two-page menu of options will appear. [Screen shot of the first options page with 3 items and 2 options activated; screen shot of the second options page (a continuation of the first page).]

On the menus you can -

•  optionally modify any beginning and ending markers for any item in those menu pages by deleting the entries in the fields; then
•  check (i.e., tick) the adjacent checkbox to activate that item; then
•  check (i.e., tick) of clear (un-tick) the optional checkbox choices at the bottom of the menu pages; and then
•  click OK.


Be sure to make the beginning and ending text markers different in some way
(for example, <B>...</B> and not <B>...<B>). This is much more reliable than using identical markers for beginnings and endings — both for you in creating the markers in a document and for the macro in finding them.

If the chosen menu item(s) is found the macro will change the item(s) to the paired markers (or paired format codes) shown on the same menu line(s) as the items you activated (i.e., ticked).


☼  It probably goes without saying, but ... always make a backup of your document before making extensive changes to it.

☼  To see how the macro works, open a new blank document and enter some text to which you can either add a text attribute (e.g., Bold) to some words or add text markers to some words. Then play the macro using the appropriate function — format codes to text markers or text markers to format codes. Repeat the test with any of the other options enabled.

☼  If you plan use the first menu option — convert format codes to text markers — but your document has some formatting that is undersirable (e.g., underlines) that should be first changed to other formatting (e.g., italics), you can do this (as a separate operation) with the ReplaceCodes macro in the Library. Then use the Change attribute codes to text markers macro to change the new formatting to your desired text markers.

☼  If you use the second menu option — convert text markers to format codes — you can also change text bracketed with markers to WordPerfect styles by first changing the text markers to format codes not used elsewhere in your document — such as Redline or Shadow (anything but Outline) or Extra Large — and then (in a separate operation) use the ReplaceCodes macro to change the Redline or Shadow or Extra Large text into your desired style, such as one of the built-in Heading styles.  For example, you could chnage <h2>...</h2> into Heading 2. Note that, unlike changing to format codes ("text attributes"), you cannot reverse this procedure with this macro (though you should be able to do it using Edit, Undo), so you might want to ensure you have made a backup first. (Thanks to Victor Warner for this tip.)


Modify menu options "on the fly": When you play the macro you can modify the text markers directly on the pop up menus. (See Note above for requirements.)

To set menu defaults: Various choices — menu checkboxes, default text markers, etc. — that are displayed on menus when the macro plays can be set in the redlined User Modification Area at the top of the macro code. Simply open the macro with Tools, Macro, Edit and follow the instructions and examples in the Modification Area.

Known Limitations

1. A small WordPerfect issue causes the macro to NOT be able to find and process format codes that might have been inserted inside a WordPerfect [Style] code (including standard paragraph Headings and Outlines), inside text variables, or inside a [Delay] code. Because such formatting is designed to be relatively "hidden" from view, the macro does not "see" the codes that cause the formatting. This is a program issue ("working as designed"), not an issue with this macro.

2. The macro will not process the "redline" and "strikeout" codes produced by File, Document, Review (or Compare). Those codes are very different from the normal attribute codes for redline and strikeout (i.e., [Redline] and [StkOut]) accessible from the property bar (toolbar) or from Format, Font. (For some more information on the Review/Compare features see here.)

3. Starting with WordPerfect X4, a new Tools, Redaction feature can mark text for deletion. However, the marks are "seen" as ordinary gray highlighting by both Edit, Find and Replace and by a macro's Search commands. Hence, the macro will skip over these items in WPX4+ (but not if the document is opened in WPX3 or earlier, where these codes will be seen as normal highlighting). A message will display to inform you about these codes and prompt you to deal with them separately.

4. The second choice on the initial menu ("Convert text markers to WordPerfect format codes") does not process items inside headers, footers, footnotes, endnotes, or text boxes. There are limitations in the macro language that make the process unreliable with the way the macro is coded.

5. [Follow on to #4:] You should examine the document and make any required changes in these areas by directly editing them. You can use the File, Document, Compare method to produce a comparison with the original document, which should make it easier to find any discrepancies.

6. [Update 2014:] A user reported that using double quote marks (") with the replacement text produces problems (macro hangs, bad formatting). Although at the time it was only one report, a suggested solution was offered to use only alphanumeric characters surrounded by angle brackets, square brackets, or parentheses. However...
    [Update 2019:]
Another user reported success by using pairs of double quote marks (a.k.a. double-double quotes) wherever a double quote mark is to appear inside a string that is also surrounded in double quotes. Hence the general syntax would be: "...""item""...". This tells the program to use actual double quote marks around the item in the string of characters. [Example of storing a text string
in a macro variable (vText) where the text string also contains a quoted word: vText="She said ""Hello"" to him."]

Page Top