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

Page updated May 18, 2017

DELCODES - Three macros to play in the current document that can remove unwanted codes

DelCodes.wcm [below] -
Deletes all format codes of one or more user-chosen types (bold, underline, tab set, etc.).

DelExtraHR.wcm [below] -
Deletes all multiple adjacent hard return codes and replaces them with a single hard return.

DelPairs.wcm [below] -
Deletes all "empty" pairs of format codes regardless of type (i.e., "orphaned" code pairs).

All three macros are in the same download ZIP file (see below).

Download DELCODES.ZIP (11/03/2016; 27,216 bytes)

Compatible with WordPerfect 7 and later 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

Disclaimer, Distribution, and Privacy Policies

[DelCodes and DelPairs are based on John Land's public domain macros.]

Related pages -

For an overview of WordPerfect codes (and some Tips and Tricks) see Reveal Codes.

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

DateRepl - Change all [DATE] codes (dynamic dates) to text (static dates)

DeSpacer - Reduces multiple adjacent spaces to single spaces without impacting any embedded codes. It can optionally relocate/remove stray single spaces

Replace Codes - Plus (see Notes and Tips in the next column -->)

ReplStyl - Replace one style with another, or remove a style's codes

DelCodes.wcm (Updated 07/25/15: v1.04 - included in download):
Deletes all format codes of one or more chosen types
from a document, such as [Bold On], [Hypertext Begin], [Para Spacing], [Tab Set], etc.

When you play the macro a menu appears (screen shot) to let you choose one or more code types from a list of codes by clicking on their names.

Alternatively you can click a button to choose all codes in the list (see also the Tip below to delete all codes without using a macro).

Not all possible format codes are listed on the menu (to keep the list relatively  short), but you can amend the list to customize the macro: See Modifications below.

Many of these codes are actually the beginning code that is part of a pair of codes that surround formatted text; hence, deleting the first code will automatically delete the second (ending) code. Other codes, such as [Tab Set], are strictly single codes and are not part of a pair. The macro will process either variety.

Certain format codes can act as "containers" for other codes and even text -- such as [Delay], [Char Style], and [Para Style] codes. If you choose to delete these codes the macro will pop up a message to alert you and let you choose to continue or exit the macro. This should help you avoid deleting these "container" codes which you might want to retain.

Be sure to see the Notes and Tips section below before using this macro.

DelExtraHR.wcm (v1.0 - included in download):
Replaces all multiple adjacent hard returns ([HRt] codes) with a single hard return in the main body text area of the current document.

[No menu appears when you play this macro.]

Purpose: This macro can be useful in cleaning up a document so that there are no extra spaces due to extra hard return codes between paragraphs.

[However, note that extra spacing can also be caused by a format code produced by a setting in Paragraph, Format, Paragraph -or- by formatting included inside a [Style] or [Delay] code. You will need to manually edit and examine these items (double-click on their codes) if you still see extra spacing between paragraphs.]

Limitations: Note that this macro does not process hard return codes inside headers, footers, footnotes, endnotes, WP comments, text boxes, etc. It only works in the main body text area of the document.

Modifications: You can set an option to also remove hard return codes that might immediately follow paragraph styles -- such as Heading styles -- in the User Modification Area at the top of the macro's code. (Paragraph styles already contain a built-in hard return; any following [HRt] code simply produces an extra empty line after that style.)

Note: What about temporary hard returns ([THRt])? The answer is found in an old Corel Knowledgebase article. See Footnote 1 below.

DelPairs.wcm (Updated 11/03/16: v1.04 - included in download):
Deletes all pairs of "empty" attribute or appearance codes
such as [Und On][Und Off] that may have been left behind (orphaned) in a document after editing. It can be very useful in cleaning up "code clutter" in the Reveal Codes window.

These paired attribute codes are considered empty if there is no text or other material (spaces, text, symbols, etc.) between them.

Note that if there are any [Bookmark] codes or [Style] codes between the pair of (presumably) "empty" on/off attribute codes, the macro will not consider the pair empty and it will skip over that pair since you probably will not want these other codes deleted.

To see the results of using this macro, open or create a short test document with a few lines of text. Open the Reveal Codes window with View, Reveal Codes.  Enter some empty code pairs at the cursor location by simply pressing Ctrl+B (bold), Ctrl+I (italics), etc. Then play the macro.

Empty code pairs to be processed can be seen in the macro code (in the ForEach..EndFor segment). Just open the macro with Tools, Macro, Edit. If a particular paired code is not found the macro skips to the next pair in the list untill all specified pairs are searched and processed.

[v1.02 adds code to take into account the state of the Reveal Codes window, and also displays the total number of deletions. v1.03 adds [Color][Color] pairs. v1.04 removed [Color][Color] codes due to complexities in some documents' formatting.]

Notes and Tips

•  To change certain format codes (e.g., underlines) to other format codes (e.g., italics), see Ron Hirsch's Replace Codes - Plus on this site.

That macro can also augment codes (e.g., change plain underlines to bold underlines). It can (optionally) delete the codes and (optionally) delete the underlying text, too. It can change an attribute to a character style for convenient, rapid modifications to the styles text later. Very useful and very popular.

•  Some format codes in a document might be included inside certain other codes (e.g., inside [Delay] codes and/or some [Style] codes), which act as "containers" to apply the formatting (and sometimes, text characters) at specific points in the document.

This happens (e.g.) when you decide to delay the onset of some formatting with Format, Page, Delay Codes. Sometimes it can be done automatically by the program itself. (See the Delay Codes page for more information.)

Hence, if you selected codes on the DelCodes.wcm menu that might also be found inside these special container codes, the menu-selected code instances inside them will not be deleted -- unless, of course, you delete the "container" code, too.

[This often useful program code-hiding feature can impact your Find and Replace operations, too, since F&R does not search inside delay codes or styles. These special codes must be manually opened (double-click on them in Reveal Codes) to view their contents and/or remove unwanted format codes that might be inside them.]

•  To delete all codes in a selection of text you don't need a macro. Simply select the block of text (even the entire document if you wish) and copy the selection to the Windows clipboard (usually with Ctrl+C). Then immediately paste the copied (and still selected) material back in place with Edit, Paste Special, Unformatted text -- overwriting the original material. This strips out all formatting codes.

Note that in WordPerfect 11 and later versions this process converts [- Hyphen] codes to regular character hyphens ("-") and [HSpace] codes to regular spaces. For more information on this, as well as for a macro (and some shortcuts) to facilitate the pasting process, see here.

See also "Be careful about deleting [Bookmark] codes" below.

•  To delete most codes (but not all codes) in a selection of text, download DelCodes2.zip (02/14/11; 7,533 bytes). This macro is similar to DelCodes.wcm, but by design (for speed) it does not have a pop up menu to choose codes. Hence you will need to open it (Tools, Macro, Edit) to do a simple edit for any codes you wish to retain in the selection of text. The default is to retain bold and italics, but you can change this. See the instructions and comments at the top of the macro.

Tip: For those using WestLaw or WestLawNext, Jim Shackleford had modified this macro to use it with those programs. See this post on Wordperfect Universe.

•  To delete one type of code in a document you don't need a macro. You can use Edit, Find and Replace, and choose the code from the F&R's Match, Codes menu. (Or you can just copy that code from the document into the F&R field, as noted in the F&R tips page here.) Then choose <Nothing> in the Replace field. It might be best to position your cursor at the very top of the document first. Also be aware that some codes have both a On and an Off code; if you delete one, the other is also deleted. [For more Find and Replace tips, see here.]

Tip: To delete a specific font code (e.g., Arial) you will need to specify the font code in the F&R dialog: Click on Edit, Find and Replace, Type (on the F&R menu), Specific codes, Font, OK. Then choose Arial and be sure to check the box to "Replace with Nothing". Then click Replace All (if you wish to delete all of them).

Related tip: To change all fonts in a selection of text to a single desired font, just apply the new font to the selection with the Font Face field on the Selected Text property bar. (Even if the replacement font is shown as the default choice in the Font Face field, you should still expand the field and then click on the replacement font name.) This causes the selection to be bracketed with a pair of [Font] codes, effectively replacing all other Font codes inside the selection.

•  Be careful about deleting [Bookmark] codes since you, the program, or a macro might use them to locate various parts of the document as part of some type of automation task.

•  For a list of format codes with brief descriptions see this thread at WordPerfect Universe: "Reveal Codes list (in PDF format)".

New in 2016 for WordPerfect X8: The Corel site has a similar PDF ("WordPerfect Reveal Codes Chart") on their download page here. Presumably, Corel will continue to provide this list for future versions.


The DelCodes.wcm macro can be modified to include (or remove) codes from the menu list.

[1] Simply open the macro with Tools, Macro, Edit.
This opens the macro for editing and displays the 9-button Macro Toolbar (i.e., a special property bar):
Macro Toolbar

[2] Then scroll down to the area that contains instructions:

"To add to the Code list ..."

Directly under the instructions in the macro's code you will see a list of format codes in two tab-separated columns, like this abbreviated version:

Global vItemList[]= {
{"[Block Pro On]";        "[Block Pro On]"};
{"[Bold On]";               "
[Bold On]"};
{"[Bookmark]";            "
{"[Very Large On]";      "[Very Large On]"};
{"[Wrd/Ltr Spacing]";    "
[Wrd/Ltr Spacing]"}

The left column contains text labels for the macro's menu list; the right column contains the actual format codes that correspond to each label.

[3] You can follow the same pattern to add or remove more labels and codes. Note these things:

The very last line item (e.g., see [Wrd/Ltr Spacing] above in the sample list) does not end with a semi-colon. All other lines must end with a semi-colon.

Adding new items to the macro's list:

The items in the right-hand column are codes and must be inserted between double quotes using the Codes button on the Macro Toolbar that should be visible (see image above; if it is not visible click Tools, Macro, Macro Toolbar). Then the macro will be able to find them if they exist in the document.

The items in the left-hand column are merely text labels typed into the macro code and used the macro's menu list (they can be any text characters). The two items are separated with a Tab for better visibility when editing the macro.

Removing items from the macro's list:

You can, of course, simply delete the item's row (i.e., the label and its code in the left and right column, along with brackets and tabs on that line), but it might be better to simply disable the item so it can be used later if desired:

Just precede the line item with two forward slashes (//). This turns the line into an inactive comment. [Side note: This was done in the alternative DelCodes2 macro in the Notes and Tips section above.]

For example, to disable the [Bookmark] item on the list:

//{"[Bookmark]";            "[Bookmark]"};

You might want to add color or highlighting to any disabled items so they are more apparent when editing the macro in the future. (Reminder: Always be sure the last item in the list does not end with a semi-colon, as mentioned above.)

[4] When done editing, save your changes with the Save & Compile button on the Macro Toolbar.

Footnote 1

[...Continue from above...]

From an old Corel Knowledgebase article:

[THRt] Codes Appear in a Document and Cannot be Deleted
Article ID: 19484  Revision Date: November 02, 1998

Text inserted on a line followed by a paragraph formating code (IE., Table, Columns, etc) cause a THRt codes to appear in a document. This code cannot be deleted.

The THRt code is a Temporary Hard Return Codes. It is a paragraph formatting codes [sic] which act the same as [SRt] Soft Return codes. The code was entered by the program because whatever formatting follows that code must appear at the beginning of a line. This is working as designed.

For example: If the word "Test" is typed and a table is created directly after the word "Test" (with the cursor on the same line) a [THRt] code will be inserted after the word "Test." This is because WordPerfect requires a table to begin on a new line. WordPerfect will remove the THRt code when the formatting is changed or in this instance the table is moved to a new line.

[From WordPerfect Universe here. Emphasis added.]