| Barry MacDonnell's
Toolbox for WordPerfect
Macros, tips, and
templates for Corel® WordPerfect® for Windows®
| Page updated Apr 18, 2021
| 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 one (or two) hard return(s) at those locations.
• 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).
[DelCodes and DelPairs are based on John Land's public domain macros.]
Related pages -For an overview of WordPerfect format codes (and some Tips and Tricks) see Reveal Codes.
Code2Txt - Change attribute codes (e.g., [Bold]) to text markers (e.g., "<B>") and vice versa
DateRepl - Change all [DATE] codes (dynamic dates) to text (static dates)
- Reduces multiple adjacent space characters to single spaces without impacting
any embedded codes. It can optionally relocate/remove stray single
Replace Codes (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/2015: v1.04 - included in download):
DelExtraHR.wcm (Updated 04/28/2020: v1.11 - included in download):
Purpose and operation
macro then processes the entire document. The changes made to your
document can usually be undone with Edit, Undo (or Ctrl+Z), but it's
always a good idea to make a backup of the document before playing the
Other types of "extra" spacing between individual paragraphs can exist
• In addition to creating extra spacing with the Enter key, extra spacing between paragraphs can sometimes be caused by a format code produced by a setting in Paragraph, Format, Paragraph.
Check to see if you have set that feature to add extra intra-paragraph spacing. (That setting adds a [Para Spacing] code to the beginning of the paragraph where it was first enabled.)
• Extra spacing between paragraphs can also be due to hard returns included inside a [Style] or [Delay] code.
But in the case of applying a Paragraph Style (such as a Heading style) in the document, you might have also used the Enter key to add an extra [HRt] followingthat paragraph style ([Para Style]) code -- effectively producing a blank line between the paragraph style's text and the beginning of the following paragraph.
If you decide you don't like the extra space at those locations, this macro can remove such extra hard returns quickly by using a checkbox option on the macro's menu -- either at the same time you play the macro to remove ordinary extra hard returns, or by playing the macro again and enabling (ticking) that checkbox. (In the latter case you probably want to be sure to choose the same number of hard returns to replace as you used during the first play of the macro.)
In the case of other types of [Style] codes or in the case of [Delay] codes, you probably will need to manually edit and examine these items (double-click on their codes) if you still see extra spacing between paragraphs.
DelPairs.wcm (Updated 05/28/2019: v1.04a - included in download):
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.]
• To change certain format codes (e.g., underlines) to other format codes (e.g., italics), see Replace Codes on this site.
That macro 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 (i.e., replace it, add to it, or remove it). For example it can change underlined text to italic text. There are 16 attributes to search from a drop list on the macro's menu. It can also pause at each item found to get your confirmation.
• 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 document or in a selection of text you don't need a macro.
There are at least two ways to do this depending on the amount of text to process.
For the entire document:
Use File, Save As to save the entire document as a special "File type" (see the bottom field in the File, Save/As windows):
• ANSI (Windows) Generic Word Processor — retains Tab codes; converts Indents to Tab codes; retains WP's end-of-line SRt codes to preserve word wrap.
- or as -
• ANSI Windows Text — removes ALL format codes; ends each line with a HRt code; converts Tabs/Indents/Margin indentation to space characters. (To remove such extra adjacent spaces see the DeSpacer macro here.)
For a selection of text:
If you want to strip out format codes from the current selection of material (even the entire document if selected) to produce "pure text"-
- first copy the selected text to the Windows clipboard (typically with Ctrl+C), then
- immediately paste the copied text back in place (or into another document) with Edit, Paste Unformatted text (in some early versions use Edit, Paste Special, Unformatted text).
Be aware this can change some format codes you might wish to retain such as (in WP11 and later versions) hard spaces, regular hyphens and soft hyphens. (See http://wptoolbox.com/tips/PSpecial.html for more.)
Still, this can be a useful technique, especially to convert outlines and numbered/lettered/bulleted lists to their plain-text versions.
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.
Related tip: To delete a specific Font Size code -- such as deleting a [FontSize: 10p] code wherever it appears in your 12-point document (including these font size codes found inside headers, footers, notes, text boxes, etc.) -- you can use either the manual method or a small macro.
Manual method: Click on Edit, Find and Replace, Type, Specific Codes, Font Size, OK. This opens the "Find and Replace Font Size" dialog.
Then specify the point size to find (in the top drop list), and check (tick) the box "Replace with Nothing" to delete that specific font size code. Finally, use the buttons of the right side of that "Find and Replace Font Size" dialog to find and replace them.
Macro method (be sure to adjust the FontSize() command below for the font size you want to delete):
// Macro begins here
// PURPOSE: Globally removes ALL specific [FontSize] codes of
// the specified point size from the current document
If (?Substructure or ?GraphicSelected)
FontSize (10p) // (<- change to the point size to remove)
// Macro ends here
To copy this code into your WordPerfect program to create a working macro see here.
• 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.
[...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.]