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 Apr 25, 2016

DYNAHEAD - Dynamic headers (a/k/a "running heads" or "floating headers") -- i.e., headers that change page-to-page with the section, topic, or heading on the same page

Three versions are available:

For WordPerfect 9 and later versions -
Download DYNA_WP9.ZIP
(v1.13; 10/19/06; 56,117 bytes)
*-
WordPerfect 11 users: See important information about using macros in the first release of WP11 (11.0.0.233) at the top of this page.

For WordPerfect 8/9 -
Download DYNA_WP8.ZIP
(v1.10a; 8/25/00; 55,742 bytes)

For WordPerfect 7 -
Downoad DYNA_WP7.ZIP
(v1.09.07; 12/7/99; 23,892 bytes; basically the same as version 1.09 for WP8/9 above but uses a wait message and status prompt instead of a progress indicator; sorry, but this probably is the last version for WP7)


Downloading, Documentation, Modifications, and Support

Related pages -

•  Headers, Footers, and Watermarks - how to start, stop, suppress, edit, change, replace, delay, overlay, and remove them

•  Also see The Header/Footer Machine for WordPerfect 8 and WordPerfect 9

Purpose

DynaHead.wcm is a macro that produces "dynamic headers" (a.k.a. "running heads," "floating headers") -- i.e., headers that change page-to-page with the section, topic, or heading on the same page.

Definitions [from "Headings or Headers"]

"Headers" are used inside (below) the top page margins, where they continue displaying their text unless they are replaced or discontinued, as discussed in Headers, Footers and Watermarks. They will be visible onscreen in Page mode (see View, Page on the top menu bar) or when you are directly editing them. By design, they do NOT appear in Draft mode.

"Headings" on the other hand are words or short phrases in the document's body text area that divide a larger body of work, such as a chapter or a section of a topic. They are created by typing some text and then (generally) applying formatting in a way that visually sets them off from other material. Headings display their text only at their current location. They can appear anywhere on the page.

[WordPerfect comes with several Heading paragraph styles (easily available on the text property bar or with Format, Styles). When these styles are applied to some text, they automatically apply their formatting to the text, such as a new font size, bold or italics, etc. They also are specially "marked" internally so that their text will be automatically included in any Table of Contents, as explained here.]

Advantages

The DynaHead macro is useful for manuals, reports, directories, company phone books, catalogs, parts lists, glossaries, etc. -- wherever you need to identify pages with a header topic that relates to a topic on the same page.

The main advantage is that you do not have to go to each page, decide on -- then select -- a heading or other phrase, copy the selection to the clipboard, create a new Header on that page, paste the copied text into the Header, justify it, exit from the Header, then go to the next page and repeat the process. DynaHead does all this for you.

Tip:  An alternative to DynaHead

On the other hand, if you just need a simple macro without all the options or automation DynaHead provides and which can simply and quickly start a new "running" header on the pages you specify, see Footnote 1 below.

Options

Several formatting options can be selected from a menu to allow you to customize the "look" or "style" of the headers, including placing the dynamic text -

•  in Header A or Header B (the default);

•  right-justified (the default), left-justified, on alternating pages (left-justified on even pages, right-justified on odd pages), or in a "dictionary" style (Word A - Word Z on each page);

•  with outdented header margins;

•  formatted with various font attributes and/or relative sizes;

•  with preceding text strings (e.g., "Chapter 5 - ");


•  with page numbering following the dynamic text.

How it works in general

The macro searches for section headings or other body text that was previously marked ("tagged") with Paragraph styles or Character styles (see also the limitations below). When it finds the chosen style on a page (you will have already chosen the style's name from the macro's menu), it copies the text to which the style was applied and pastes it into a new header on the same page. It then proceeds page-by-page to the end of the document, creating new "dynamic" headers as it goes.

For example, you could set DYNAHEAD to find all instances of a standard WordPerfect paragraph heading style that exists in the document, such as the "Heading 2" style. (The standard style named "Heading 2" must have been applied to text somewhere in the current document. Many users find these standard Heading styles convenient since they also cause their text to automatically appear in any Table of Contents you might generate.)

Or, you could have DYNAHEAD find a user-defined (a/k/a custom) style such as "MyStyle3" that was used in the document.

The text to which these styles were applied will appear in the Header on that page, formatted in the manner dictated by the options you chose on the macro's menu.

Tip: Whichever type of Header you use (A or B) for dynamic headers, you could use the other Header (B or A) for a chapter title. Simply create the chapter Header manually (Insert, Header/Footer) at the top of each chapter, and use the opposite text justification so that the title does not overlap Dynahead's material.

How it works on each page

The first instance of text marked by the chosen style that is found on a page is copied to the header on that page. The last instance of marked text (which could be the same as the first, or it could be different) is stored and used on any subsequent page that doesn't have any marked text, so that there is a "carry-over" effect on intervening pages.

In other words, all pages will always have dynamic headers. [If dictionary-style headers are chosen, the last marked text is used inside the same header, thus: "Word(s) A • Word(s) Z". Dictionary-style headers also alternate their justification on odd/even pages.]

Notes and known limitations

•  Paragraph styles -- such as the five WordPerfect default Heading styles -- end with a hard return, and are often used for document headings or other sectional divisions. Character styles, on the other hand, can be applied to words, phrases, or larger blocks of text, and do not require a hard return. Dynahead works best when either type of style is only applied to short blocks of text, such as a word or a phrase; otherwise, you could produce headers that are too large or "crowded." (See also the known limitation about styles that span more than one page, below.)

•  Document
("Open") styles are not supported. Unlike Paragraph and Characters styles, which are produced by a pair of codes, there is no ending code in a Document style. Because of this characteristic the macro cannot find the end of the block of Character-style-marked text; therefore it cannot copy that text to the page headers. Only Paragraph and Character styles are supported.

• 
If you later add or remove text or graphics from your document, play DynaHead again to refresh the headers. Dynamic headers of the type used here are not automatically updated when you make add/remove changes to your document. (A message displays after the macro completes its work to remind you to replay the macro after revising a document.)

• 
If you plan on using a Table of Contents (TOC) or an Index, you should create the TOC or Index after playing DynaHead -- or at least regenerate the TOC/Index after you have finished with DynaHead. DynaHead creates headers on every page, and since headers (like footers) "encroach" on the body text area, the creation of headers can push body text downward into the document due to the decreased size of the body text areas on each page. This can cause a pre-existing TOC or Index's page numbering to be incorrect for some pages. It is a good idea to regenerate a TOC and Index after playing DynaHead.

• 
A style (i.e., the marked text to which a style has been applied) that is split over two pages may sometimes produce incorrect headers because the macro searches for the beginning and ending of a given text style on a page-by-page basis. Try to confine text that is marked with a style to a single page. (You can "block protect" styles: See "BPSTYLES - Block protects paragraph styles (e.g., "Heading 2") and following body text".

• 
Hidden text codes ([Hidden] and [Hidden Txt]) can be problematic (in WP8 they caused some search code to go into a loop).

• 
Multi-page tables can slow down the macro as it locates the top of each page. On occasion these tables may cause the macro to produce improper header text on the last page, or even cause the macro to fail.

One solution that has ben reported to work is to temporarily remove the table (i.e., copy it to an empty document), play the DynaHead macro, then insert the table back in the appropriate location. Use Reveal Codes to ensure that you also copy the table's [Tbl Def] and [Tbl Off] codes, which include the table's formatting.

•  Pre-existing [Suppress] codes on Page 1 can be problematic. For example, if the macro has been previously played on the same doument with the "Suppress header type (A or B) on page 1" option selected, and is subsequently played with this option deselected, a header still will not appear on Page 1. In this event, manually delete the appropriate [Suppress] code in the Reveal Codes window. For more on the suppress feature, see here.

Note that the macro language cannot tell what type of suppress code it finds in a search, so coding around this problem is not possible since a user may have used several such codes with differing purposes.

Tip

If you want to add your own custom style names to the menu's drop list, here's a procedure (tested in WP12) that should do the job, but it requires editing the macro and using the macro's Dialog Editor -- something that probably will appeal only to intermediate or advanced users.

Example: Suppose you have a custom paragraph style named "Stepped 2." Open the macro for editing and carefully follow these steps.

Step 1.

Click the Dialog Editor button on the macro toolbar. The PerfectScript dialog window appears.

Step 1a.

Double-click "menu1" to open the standard (non-metric) DynaHead menu for editing. ("menu2" is for metric users.)

Two new dialogs open on screen: the PerfectScript Dialog Editor toolbar, and the DynaHead menu (in dialog editing mode).

Double-click anywhere on the DynaHead menu's style name drop list to being up the Combo Box Properties dialog.

Step 1b.

Click the Create/Edit list button in the Combo Box Properties dialog; in the "List item:" field, enter (without quotes) "Stepped 2" and click OK. (Note that names are case-sensitive.) The new style name will be added to the list.

Repeat Step 1b for any other custom paragraph style names you want to add. (When you are using Create/Edit List, you can select an item and use the Move Up and Move Down buttons, as well as Set Initial to set the initial menu selection the user will see.)

When you are finished adding to the "List items:" field, click OK from the Combo Box Properties dialog to dismiss the dialog.

Step 1c.

On the other "floating toolbar" dialog (i.e., the PerfectScript Dialog Editor dialog), click the Save button (or use File, Save from the Editor's menu). Then use File, Close from the Editor's menu.

You should now be back in the main macro document window, editing it.

Step 2.

Now you need to modify some of the macro's commands.

At about line 137 in the macro code, you'll see this line of code (it will be all on one line):

Default: vStyleNameorEnum := vEntryStyle Break // Store user-defined style

Just above it, carefully enter this line of code (type all on one line):

CaseOF "Stepped 2": vStyleNameorEnum := "Stepped 2" Break

(Note that style names are case-sensitive.)

Repeat Step 2 for any other style names you added in Step 1b.

Step 3.

When finished, click the Save & Compile button on the macro toolbar. This will save the changes you made in Steps 1 and 2.

Play the macro on a document that has the Stepped 2 style in it.

Disclaimer, Distribution, and Privacy Policies

Page Top



Footnote 1

[Continued from above...]

If you just need a simple macro (i.e., without the automatic header formatting options above) that can quickly start a new "running header" on various pages you specify, here's a small macro that can do it (see macro code below in dark red).

Tips

☼  Don't forget that you can use the other header type in the same document -- the second type will overlay the first. For example, if you use HeaderA for the running header you can use HeaderB for continuous page numbering, etc., on the same pages as the running heads. See "How to overlay them..." here so that the content of HeaderA does not conflict with HeaderB, and vice versa.

☼  For "running footers" see the second macro below.


Purpose

The raw (plain text) macro code below, when copied into your WordPerfect,

•  inserts the currently selected text in your document into a new Header starting on the current page.

For example, you could select a short phrase such as a heading, play the macro, and it will create a header at the top of that page containing the selected text. [N.B.: The header will continue to display unless a new header of the same type (A or B) is set further in the document -or- unless the header is discontinued with Insert, Header/Footer. For more on using headers, footers, and watermarks see here.]

•  On the other hand if no text was selected the macro pops up a dialog to get up to 100 characters of text from the user. (The "100" is arbitrary and you can change it.) Then it inserts it into a new Header starting on the current page.

Operation

Select some text and play the macro, or just play it at the current cursor location.

Notes

¤  If the macro is played more than once on a page, the first inserted header on that page will be displayed, and the last inserted header on that page will be displayed on the next page (if any). (Exception: If played again in the same line or paragraph, the new [Header] code will replace any [Header] code of the same type (A or B) in that particular line or paragraph. This is the way the program works.)

¤  The only thing inserted into the headers will be the text you selected before playing the macro, or the text you input into the pop-up dialog. Either way the text will be in plain text format. (You can always edit any header later by clicking inside it.)

To delete a particular header, just delete the [Header] code on the page where the header begins. (You can simply drag the code from Reveal Codes.) If you deleted the wrong header code, press Ctrl+Z to restore it -- or just play the macro again.

Tips

☼  It can be helpful to open Reveal Codes before playing the macro to see where the new [Header] codes are being placed and their effect on document headers.

☼  Test it on a copy of a multipage document to see how it works.

☼  You can assign the macro to a toolbar button, keyboard shortcut, or menu: see here.

Installation and modifications

To copy the code below into your WordPerfect program to create a working macro, see here. (Copying minimizes typing errors, especially with punctuation.)

The yellow highlighted code shows where you can make changes to the macro's operation: For example, you can change the type of Header to use (Header A is the default in the "running headers" code below) and change the header's text justification (the default is Left justified).

[Lines beginning with double slash marks (//) are programmer comments and do not affect the macro's functioning.]

Running headers macro

// - - - Macro code begins here - - -

// BE SURE to set the type of header (A or B) to use here:
vHeaderType:="A"  // (retain the double quote marks)

vHR:=NToC(0F90Ah) // (stores a hard return code, used in dialogs below)

// Ensure a header type was correctly set:

vHeaderType:=StrTrim(ToUpper(vHeaderType);;TrimEnds!)
If(vHeaderType != {"A"; "B"})
    Messagebox(;"Error";
    "The macro specified header type """+vHeaderType+""""
    +vHR+vHR+
    "You must use either header type ""A"" or ""B"" in the macro code")
    Quit
Endif

OnCancel(End@)
// If no text was selected, display a small dialog to get the text; else
// insert the selected text in a new header on that page.
If(?BlockActive=False)
Label(Top@)
    GetString(x; "Enter the text to use in a new HEADER  "+vHeaderType+
    "  [ up to 100 characters ]."+vHR+
    "Cancel or Esc quits without creating a new Header.";
    "Insert New Header"; 100)
    If(x="") Messagebox(;"Oops!";"Enter some text!") Go(Top@) Endif
Else
    x:=StrTrim(?SelectedText;;TrimEnds!) // (removes spaces from both ends)
Endif

PosLineBegin  // (place new [Header] code at beginning of line/paragraph)

If(ToUpper(vHeaderType="A"))

    HeaderA(Create!;;Off!) // (On! forces header to use document's margins)
Endif
If(ToUpper(vHeaderType="B"))
    HeaderB(Create!;;Off!) // (On! forces header to use document's margins)
Endif

Justification(Left!)  // (use either Left!, Center! or Right!)
Type(x)  // (insert the desired text into the header)

SubstructureExit  // (exit from the header)
Label(End@)
Quit

// - - - Macro code ends here - - -

[This macro was inspired by a macro posted by Charles Cork on WordPerfect Universe here.]

= = = = =

Running footers macro

For those who wish to use "running footers" instead of "running headers" here's the same macro above but using footers instead of headers.

[Please read the comments above the first macro for additional information and instructions; just read "footer" where it mentions "header".]

// - - - Macro code begins here - - -

// BE SURE to set the type of footer (A or B) to use here:
vFooterType:="A"  // (retain the double quote marks)

vHR:=NToC(0F90Ah) // (stores a hard return code, used in dialogs below)

// Ensure a footer type was correctly set:

vFooterType:=StrTrim(ToUpper(vFooterType);;TrimEnds!)
If(vFooterType != {"A"; "B"})
    Messagebox(;"Error";
    "The macro specified footer type """+vFooterType+""""
    +vHR+vHR+
    "You must use either footer type ""A"" or ""B"" in the macro code")
    Quit
Endif

OnCancel(End@)
// If no text was selected, display a small dialog to get the text; else
// insert the selected text in a new footer on that page.
If(?BlockActive=False)
Label(Top@)
    GetString(x; "Enter the text to use in a new FOOTER  "+vFooterType+
    "  [ up to 100 characters ]."+vHR+
    "Cancel or Esc quits without creating a new Header.";
    "Insert New Footer"; 100)
    If(x="") Messagebox(;"Oops!";"Enter some text!") Go(Top@) Endif
Else
    x:=StrTrim(?SelectedText;;TrimEnds!) // (removes spaces from both ends)
Endif

PosLineBegin  // (place new [Footer] code at beginning of line/paragraph)

If(ToUpper(vFooterType="A"))

    FooterA(Create!;;Off!) // (On! forces footer to use document's margins)
Endif
If(ToUpper(vFooterType="B"))
    FooterB(Create!;;Off!) // (On! forces footer to use document's margins)
Endif

Justification(Left!)  // (use either Left!, Center! or Right!)
Type(x)  // (insert the desired text into the footer)

SubstructureExit  // (exit from the footer)
Label(End@)
Quit

// - - - Macro code ends here - - -