| Barry MacDonnell's
Toolbox for WordPerfect
Macros, tips, and
templates for Corel® WordPerfect® for Windows®
| Page updated Nov 3, 2016
| 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).
[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)
- Reduces multiple adjacent spaces to single spaces without impacting
any embedded codes. It can optionally relocate/remove stray single
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):
DelExtraHR.wcm (v1.0 - included in download):
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
[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.)
DelPairs.wcm (Updated 11/03/16: v1.04 - 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 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.