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 Nov 26, 2021 |
|
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 |
||
Related pages - • 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.
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. 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.
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.] • 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.
|
|
Disclaimer, Distribution, and Privacy Policies | ||
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.] UPDATE (Nov. 2021): If you want to create left-justified
headers (as with the code above) but you wish to use a smaller font and
with the current page number displayed "flush right," just add this code just underneath the Type(x) command:
FlushRightWithDotLeaders // or (e.g.) use FlushRight
PageNumberDisplay SelectParagraphPrevious AttributeRelativeSize (Small!) SelectOff HeaderSeparationDistance (0.334") // (normal = 0.167" from text) = = = = = 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 - - - |