Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate |
![]() Toolbox for WordPerfect |
||
Macros, tips, and
templates for Corel® WordPerfect® for Windows® |
Page updated Mar 24, 2021 |
|
REPLSTYL -
Replace one style with another, or remove a style from the document |
||
Related pages - • Replace Codes - A macro that can quickly change text attributes (e.g., bold, underline, italics, large size, etc.) by replacing, adding, or deleting a chosen attribute wherever it appears in the current document. [See the left column on that page for other related macros.] • For more on WordPerfect styles, see the main Styles page (and the links in the left column there). Disclaimer - Copyright, Modification, Distribution of Materials and Privacy Policy. |
Purpose / Overview ReplStyl.wcm (v2.0) is a macro that can replace a Paragraph, Character, or Document (a.k.a. "Open") text style wherever it is found in the document with another chosen style. Tip: For more on these 3 types of text styles and how they work and interact, see the Styles page. For Outline styles, see the Notes section below.
It can also remove all instances of the named style rather than replace them. There is also an option to pause the macro and prompt the user for confirmation at each instance found in the document. A menu appears when you play the macro to let you quickly choose any of the five standard Heading styles to replace (or remove). Or you can enter (in a menu field) the name of a custom text style which exists in the default template that spawned the document or which was used (or saved) in the current document. [Screen shot of menu] Comparison to simply changing (editing) a WordPerfect style Depending on a setting in the program's Styles Editor, WordPerfect allows you to globally change an existing style throughout a document by simply editing the style, thus: 1. Click on
Format, Styles, and choose a style; then click Edit to bring up the
Styles Editor to make your changes. Or, you can simply double-click the
style's code in Reveal Codes to bring up the Styles Editor.
2. While in the Styles Editor you can check (tick) the box, "Automatically update style when changed in document" so that later changes can be made globally throughout the document either in the Styles Editor or by merely applying a formatting change (such as a special color, etc.) to any instance of text to which that style was applied. However ... It may be more desirable or more convenient — and often faster — to replace one style with another style (usually of the same type, Paragraph, Character, or Document) everywhere it was applied in the document, while also (optionally) allowing the macro to pause at each instance found to ask you for confirmation. This is the main purpose of this macro. As noted, the macro also lets you remove the style (but not the text to which the style was applied) by deleting the style's codes. You can choose to do either of these things in one operation, or (as also noted) have the macro pause for confirmation at each style's location. In the latter case the macro will have opened the Reveal Codes window so that you can see the style codes at that location. Notes • Styles in the document The
style you choose to replace (or remove), as well as the style to use as
a replacement, must already exist in the document (even if not yet
applied to text) or in the default template. If not, the macro will pop
up a message and then return to the menu, where you can either make a
different choice or cancel the macro and apply the missing style to
some text.
Tip
If you don't know (or can't remember) the name of the style to use as a replacement — existing styles in the document should appear in the Select Styles field on the Text property bar — then try this: Click on Format, Styles to open the Styles dialog. Then click the Options button on that dialog; then click on Settings... to open the Style Settings dialog. Try enabling the checkboxes on the left side of that dialog and click OK to return to the Styles dialog, where all styles should appear in the scrollable "Available Styles" list. Take note of the exact name of the desired style and click Close to return to your document. Since version 2.0 this macro also works to replace Document ("open") styles as well as remove them. Document styles do not use paired codes: Such open styles have only a beginning code, which means the style will remain in effect if and until it is changed further down in the document. It's also important to note that styles can exist inside other styles ("nested" styles) as well as in Delay Codes. Therefore, a WordPerfect manual search (Find and Replace) or a macro search cannot find these nested styles (with a macro it might require a great deal of extra coding). Solution: This is "working
as designed" — probably because the existence and function of such
nested styles depends on the intent of the person who created them, and
the results of a complicated search routine targeting them might be
problematic. The best solution is to manually edit such suspected
nested styles to remove or modify them. (See here for related information.)
• Replacements Most often you will replace one type of style with another style of the same type.
But sometimes you might want to replace a style with a style of a
different type. The order of precedence with replacements is set by
WordPerfect. Order of precedence for replacements
1. If you replace a Character style with a Paragraph style, the latter will apply the new style to the entire current paragraph (hence the name "paragraph"). 2. If you replace a Character style or a Paragraph style with a Document("open") style, the latter will apply the new style to the searched text and following text (hence the name "open"). You can determine the type of text styles (by name) that can be used by this macro when it searches for the style: The type of style in effect (Paragraph, Character, or Document) should be visible on the code itself in Reveal Codes. Just pass your cursor over the code displayed there. Or you can double-click on the style's code (if available) in the document's Reveal Codes window and look under 'Type' in the Styles Editor that pops up. [Alternatively, use Format, Styles to display the Styles Editor, where the styles should be listed; choose the style and click Edit to determine the style's Type.] [For more on these three types of text styles and how they work and interact see Styles.] • Removals This
macro can remove any of the 3 types of style. This is because it always
searches for the [Style] code with the specified name and deletes it.
And since Paragraph and Character styles are paired codes, deleting just the first code in the pair will simultaneously delete the entire style at that location.
When removing styles, if you choose "Prompt for confirmation" on the macro menu, the macro will obviously run more slowly as it pops up a Yes/No/Quit dialog on your screen. To help you see which style is currently being processed when the macro pauses for confirmation, look in the Reveal Codes window, which should be open (if it was not already open) while the macro runs. Tips: If you need to remove a style containing format codes but you want to retain those format codes in the document, simply click on Format, Styles, <choose the style>, Options, Delete, "Leave formatting codes in document," OK. Later, you can change these (or any) text attribute codes (bold, italics, etc.) in the document to different codes (or just remove them) with the Replace Codes macro in the Library. That macro can also replace text attributes with a custom style. • Specifying the style to process On
the macro's main menu be sure to enter any custom (i.e., user-created)
style's name exactly as it appears in the Select Style drop list on the
property bar for the document. Check to see if the style you need is
already listed there (e.g., one of the Heading styles); if so, simply
click on the name to choose it.
You can also open Format, Styles on the WordPerfect menu to view the available styles: All current document and template styles will be displayed in that dialog if the Options [see button] were set to display them, but note that many "system" styles (other than the previously mentioned Heading styles) will not work as intended with this macro (e.g., Footnote, Footer, etc.), so there is little point in displaying them in that dialog's list. • Outline styles If you are trying to replace a paragraph outline (e.g., Para Style: Level 1) with another paragraph outline (e.g., Para Style: Legal 1), try using the more direct approach of
clicking Insert, Outline/Bullets... (or double-click the [Outline] code
above the outline items) and choosing the new outline from the Bullets
& Numbering dialog. You probably don't need to use this macro for
such a purpose.
In fact, since a
WordPerfect outline is really a combination of a paragraph number and a
"level" style (click on Edit in the Bullets & Numbering dialog and
you'll see the link between paragraph numbers and specific styles at
each outline level), using this macro to replace one outline with
another will perform only half the task by replacing just the style
portion of the outlines. You would still need to reset the numbering
for each paragraph level, too.
[To do this, double-click the [Outline] code at the at the top of the document or at the beginning of the outlined material, and when the Bullets & Numbering dialog opens, select the new outline's name and click OK. This will reset the numbers for the outline that is present in the document. (For more on WordPerfect outlines see Outlines.)] • Back ups It is always a good idea to play any macro on a copy of your document — at least until you are comfortably familiar with its operation. • Modification You can set some menu defaults in the redlined User Modification Area at the top of the macro code
Alternative (old-time manual method) • Old, arcane tip to replace one style with another style: It is possible to swap two styles using a
three-step "ABC" method: To swap style "A" with style "B," first create
a temporary style "C" — perhaps a simple style (Character or
Paragraph, depending on style A's type) created with little or no
formatting, using a QuickStyle. The temporary style is used to move
style A out of the way temporarily. Then use this macro to replace A
with C (i.e., A becomes C), then replace B with A (i.e., B becomes A),
then replace C with B (i.e., C — which was A — becomes B).
Schematically: A => C, B => A, C => B. It might be helpful to use a QuickStyle (style
C) that is readily identifiable (such as a redlined or highlighted
style) to help identify where you are in the three-step process. For
example, place the cursor on a redlined word in the document, and
select "QuickStyle" from the Select Style drop list on the text
property bar. Give the QuickStyle a name, choose Paragraph or
Character, and click OK. Use this temporary style as style C in the ABC
method.
|
|