|
|
|
To put these thoughts in action, we employ the IF field. The basic IF field compares two values and returns one of two user defined results. Take the following IF field for example: { IF {PAGE} = {NUMPAGES}"""Your Footer Text"} The IF field compares the page number to the total number of pages. If the condition is satisfied (i.e., the two are equal), the IF field returns the text contain within the first pair of speech marks "" (in this case nothing). If the condition is not satisfied, the IF field returns the text within the second pair of speech marks "Your Footer Text." Lets look at the other approach. { IF {PAGE} < {NUMPAGES}"Your Footer Text"""}. Do you see the comparison here? If the page number is less than the number of pages, the field returns "Your Footer Text" if not, the field returns "" (or nothing). Put either of the above IF conditional fields in your document footer and your problem is solved!! How about "I want my header to appear on the last page only. What do I do?" Ask your self the question and develop a logical IF expression to provide the answer: {IF {PAGE} = {NUMPAGES}"Your Header Text"""} How about "I want my header text on page 5 and 6 only!!" Well this is a little tougher and requires a bit of thinking, but if we "nest" a couple of IF fields the solutions is at hand: { IF {PAGE} >= "5""{IF {PAGE}<="6""Your Header Text"""}"""}. Here the IF field makes the first comparison and either returns nothing "prints no header" for pages less less than 5 or moves to the second "nested" IF field for a second comparison. In the second comparison, the IF field either returns nothing "prints no header" for page numbers greater than 6 or prints a header for page 5 and 6. Note: The constructions shown above make liberal use of the empty double speech marks for demonstration purposes. Speech marks can serve as place markers and are not actually required when the value to be returned is already enclosed in field code brackets or if a null value is at the end of the sting. For example, the highlighted speech marks in { IF {PAGE} >= "5""{IF {PAGE}<="6""Your Header Text"""}"""} are optional and may be omitted. The Word Help files provide further explanation of IF field construction with examples. Advanced Conditional Headers and Footers Some documents require a conditional header or footer based on text content. One example is a classified document with SECRET, CONFIDENTIAL or UNCLASSIFIED elements. The standard (at least the military standard) is that each data element (e.g., paragraph) is marked with its proper classification and the Header and Footer is marked with the highest classification level contained on the page. This can be a real challenge and using section breaks to create the proper header and footer can lead one to the brink of madness. I asked the question how to do this more efficiently and fellow MVP Peter Jamieson provided the answer. Peter developed a brilliant combination of of QUOTE, SEQ, IF, and PAGE fields to simplify this task immeasurably. I will let you have a look at the fields first and then explain how they work. The first two fields are used to mark the classification of the text: { QUOTE (S) { SEQ S \r{PAGE} \h}} { QUOTE (C) { SEQ C \r{PAGE} \h}} Here is the field used in the header and footer: { IF { SEQ S \c } = {PAGE}"SECRET""{ IF { SEQ C \c } = {PAGE}"CONFIDENTIAL""UNCLASSIFIED"}"} After applying the text marker fields to each element of classified text, the fields will display (S) and (C) respectively. The display results from the QUOTE field which returns literal text (i.e., (S) in one case and (C) in the other). There is more at work in these two fields however. You will note that each QUOTE field contains a "nested" SEQ field. SEQ fields display sequential numbers and require a sequence ID (here the letters S and C are used for the sequence identifiers). The two SEQ fields here are further refined by field switches and a "nested" PAGE field. The first switch "\r" resets the sequence number to the number following the "r." In these examples that number is defined by a {PAGE} field. This means that if one of these SEQ fields is included on page 5 then the SEQ field will return the number 5. We don't want to see or print these numbers so the second switch "\h" is used which instructs Word to hide the SEQ field result. The Header and Footer employs the now familiar "nested" IF field. Here we will use the values of the hidden sequence numbers created by the text marker fields to compare with the page number and determine the proper header and footer text. Remember IF the page contains text marked (S) or any combination of text marked (S), (C), or unclassified text the header and footer must display SECRET. If the page contains only text marked (C) or any combination of text marked (C) and unclassified text the header and footer must display CONFIDENTIAL. If there is no (S) or (C) marked text the header and footer must display UNCLASSIFIED. The first "nested" SEQ field { SEQ S \c } employs a switch "\c" which instructs the field to return the value of the nearest "preceding" sequence number. Here things may begin to appear odd. If you print a Word document or look at it on the screen, the main body text on page 1 obviously follows the page 1 header text. However a Word document is not "printed" or "displayed" until all the internal calculations and formatting are completed behind the scene. Backstage a Word document is sort of like one of those static anatomical charts where you lift the skin layer to to see the muscle, lift the muscle layer to see the bones, etc.. In the SEQ field calculations, the main body text on page 1 is synonymous with the skin, the headers and footers are synonymous with the muscle. This means all of the {SEQ S \r{PAGE} \h} fields in the main body text on page 1 actually precedes the {SEQ S \c} field in the header and footer on page 1. Lets collapse the header and footer "nested" fields one at a time to see what is happening. Lets assume that there is a {SEQ S \r{PAGE} \h} text marker field on page 5. This field will return the value 5 as demonstrated previously and hide the result. Since this hidden field value 5 precedes the {SEQ S \c } field in the header and footer field, it will also return a value 5. { IF { SEQ S \c } = {PAGE}"SECRET""{ IF { SEQ C \c } = {PAGE}"CONFIDENTIAL""UNCLASSIFIED"}"} What will the {PAGE} field return? { IF 5 = {PAGE}"SECRET""{ IF { SEQ C \c } = {PAGE}"CONFIDENTIAL""UNCLASSIFIED"}"} We are in the page 5 header and footer so the field will return the value 5. { IF 5 = 5"SECRET""{ IF { SEQ C \c } = {PAGE}"CONFIDENTIAL""UNCLASSIFIED"}"} It should be clear that IF 5=5 (It does) that the IF field will return the text inside the first set of speech marks, or "SECRET" OK what if there was no (S) text mark field on page 5. Page 5 contains a combination of (C) marked and unclassified text only. The last (S) text mark field was found on page 4. Here the first part of our collapsed field would look like this: { IF 4 = 5"SECRET""{ IF { SEQ C \c } = {PAGE}"CONFIDENTIAL""UNCLASSIFIED"}"} 4 does not equal 5, so the first condition is not met and the field returns the result found in the second pair of speech marks. This is another IF field: { IF { SEQ C \c } = {PAGE}"CONFIDENTIAL""UNCLASSIFIED"} Lets continue to collapse the fields { IF { SEQ C \c } = {PAGE}"CONFIDENTIAL""UNCLASSIFIED"} {IF 5 = {PAGE}"CONFIDENTIAL""UNCLASSIFIED"} { IF 5 = 5"CONFIDENTIAL""UNCLASSIFIED"} Again IF 5=5 (It does), the IF field will return the text inside the first set of speech marks, or "CONFIDENTIAL" If there are no (S) or (C) text marks on page 5 then neither condition will be met and the field will return UNCLASSIFIED. Bonus Tip: To make use of the text marker fields more efficient, you should create AUTOTEXT. Select the result of an updated (S) field and press ALT+F3. Name the entry (I use secret for (S) and confidential for (C)). Repeat for an (C) field entry. Use these AUTOTEXT to easily mark your classified text. Click here to download a template containing the Header and Footer field codes, text mark field codes, and text mark AUTOTEXT entries. Looking for something else?
| ||||||||