| Barry MacDonnell's
Toolbox for WordPerfect
Macros, tips, and
templates for Corel® WordPerfect® for Windows®
| Page updated Mar 6, 2017
|DeSpacer - Reduces multiple adjacent spaces to single spaces. It can optionally relocate/remove stray single spaces.|
• Alternative - If
you are not concerned with relocating some single spaces or possibly removing some adjacent format or bookmark codes (see
DeSpacer's description in the next column), see the simpler macro below in Footnote 1.
• Similar "clean up" macro - DelExtraHR.wcm deletes all multiple adjacent hard return codes ([HRt]) and replaces them with a single hard return. Extra hard returns can be caused by pasting material, overuse of the <Enter> key to separate text, etc. The macro is included as part of a small suite of macros that remove unwanted format codes. See DELCODES in the Library.
• To find multiple adjacent periods (full stops), commas, etc. use Grammtik (on the Tools menu). It will flag these items -- as well as duplicate adjacent words
-- which are often left behind after lots of cut/copy and paste
operations. Once flagged you can delete the extra ones directly from
the Grammatik dialog.
 Download the
DESPACER.ZIP archive file (click the link at top of the left column on
this page) to any convenient folder or to your Windows desktop. DESPACER.ZIP is merely a "container" that holds the actual macros.
 Extract the
macros from that ZIP file and place them in your WordPerfect default
(or supplemental) macro folder so the program can find them. [If you
need help with this see the instructions in the "Downloading..." link.]
 Open the document that you want to "despace." Play the Despacer.wcm macro with Tools, Macro, Play (or Alt+F10). You can choose various options on the menu that pops up. [Screen shot] Click OK. A "Working ... Please wait" message will appear and you can cancel operation from it as well as from the main menu.
☼ Recommended: If you choose to relocate extra spaces adjacent to format codes -- the first option on the pop up menu -- it is recommended that you first clean up "empty" code pairs (e.g., [BoldOn][BoldOff]) with the DelPairs macro in the Library. This should make DeSpacer more accurate with respect to the first option.
☼ You can play the macro on a copy of your document (File, Open, <name>, Open as Copy), then do a comparison (File, Document, Compare) of the copy with the original document to see what has been changed. (File, Document, Compare is not available in the some editions.)
☼ You can assign the macro to a toolbar, keyboard shortcut, or menu for easy access. See here.
¤ If your document contains hard spaces (i.e., [HSpace] codes, entered from your keyboard with Ctrl+spacebar), the macro will not treat them as spaces and thus will not remove them. You can use Reveal Codes to determine if any remaining (and unexpected) extra spaces are hard spaces and not normal (spacebar) space characters.
¤ If the macro processes a lot of spaces, you may not be able to undo the change with Edit, Undo (which is limited to 300 levels of undo). Normally, the macro will process the document with just one or a few levels of Undo -- but there may be circumstances where this is not true. Therefore you should either abandon the changes and Close without saving (then re-open the document), or use File, Save As, and save it with a different name.
¤ Processing a large document can take time, given the way the macro operates. You may want to play it on a copy of the final draft of your document, after all other edits are done.
¤ Extraneous spaces can be almost anywhere in a document. While the author has tested this macro "nine ways from Sunday," there may be cases where spaces are not removed, or are relocated improperly. If so, please contact the author and he will try to solve the problem and make the macro more robust. In light of this, however, it is recommended that you always work on a copy or a backup of your document.(See disclaimer.)
Note: This macro is based on the first option in the DeSpacer.wcm macro above (screen shot of DeSpacer menu), which can relocate solitary spaces that might be misplaced adjacent to many paired format codes. If you use DeSpacer with that option enabled, you don't need to use Relocator on the same document (unless you want to). [You can also download just the Relocator macro here.]
¤ It is recommended that you first clean up "empty" code pairs (e.g., [BoldOn][BoldOff]) with the DelPairs macro in the Library. This should make Relocator more accurate.
¤ The exceptions to relocating spaces in the above manner are spaces adjacent to Font (type or size) codes, where users may want spaces in specific locations when a new font or size is applied. Therefore, spaces adjacent to [Font] and [Font Size] codes are skipped during macro play.
¤ Only single spaces are relocated since it must be assumed that some users actually desire multiple spaces in certain locations. If you want to remove all extra spaces use the author's DeSpacer macro (see above).
If you are not concerned with relocating some single spaces or possibly removing some adjacent format or bookmark codes (see the DeSpacer description above), here's a much simpler macro that should do the job that DeSpacer does.
It can also optionally retain all double spaces (see the Note below) as well as single spaces, but it does not have the options included in DeSpacer (see the DeSpacer menu here).
To copy the macro below into your WordPerfect program, see the simple instructions here.
Note: If you want to retain all double spaces in the current (working) document, you need to add an extra space character to the SearchString() command below (the default is 2 spaces, so change it to 3 spaces with your spacebar).
// Macro code begins
pResetFindReplace () // (call a procedure to set search parameters to the default)
PosDocVeryTop // (start at the top of the document before all other codes and text)
OnNotFound(EndNow@) // (when NOT found, jump down and exit)
MatchPositionBefore // (when found, place the cursor to the left of the item)
SearchString(" ") // <= 2 space characters between the quotes
While(True) // (creates an endless loop until a Not Found condition exists)
SearchNext(Extended!) // (searches in headers, footers, graphic boxes, etc.)
pExitSubstructures () // (call another procedure)
// Macro exits here:
Procedure pResetFindReplace ()
// Only one Match* command can be active at any one time:
SearchWordForms(No!) SearchWrap(No!) MatchLimit(No!)
Procedure pExitSubstructures ()
// Exit from any header, footer, footnote, endnote, text box, graphic caption, etc.:
If((vSubDoc=10) or (vSubDoc=11)) BoxEnd(Save!) EndIf
// If the cursor is in an image or a text box is selected, exit from it:
If(vBoxType=1 or vBoxType=3) BoxEnd(Save!) Endif
// Macro code ends