4.5.6 Headers and footers

Headers and footers

Have you ever noticed a document that included the chapter title at the top or said something like "Page 3 of 17" at the bottom of each page? Items like those are called headers and footers. Word has tremendous support for them, allowing you to put different headers on the first page of each section of a document than on the other pages, and to create separate headers and footers for odd and even pages.

Interactively, you access a document s Header and Footer through the View menu (see Figure 9), which makes them available for editing and brings up a special toolbar for the purpose. The toolbar includes tools for inserting common header and footer items like page numbers, date and time, and so forth. However, headers and footers can hold any text at all, as well as graphics like company logos.

Figure 9. Adding headers and footers. Use the View menu to make headers and footers visible interactively, so you can add to them. In the object model, they re represented by HeaderFooter objects.

The kinds of headers and footers in a document (different first page, different on odd/even pages) are controlled through the PageSetup object and are discussed in the section "Setting up pages" earlier in this chapter. Header and footer content is stored in HeaderFooter objects, which are part of a HeaderFooters collection, accessed through the Headers and Footers properties of the Section object. Any section can have up to three of each, accessed via the constants wdHeaderFooterPrimary (1), wdHeaderFooterFirstPage (2), and wdHeaderFooterEvenPages (3).

Each HeaderFooter object represents a single header or footer. The key properties are shown in Table 11.

Table 11. The HeaderFooter object. Despite its name, each instance represents a single header or footer.

Property

Type

Description

Exists

Logical

Indicates whether the specified header or footer exists. Contradictory as this property seems, it makes sense when applied to a member of the HeadersFooters collection.

IsHeader

Logical

Indicates whether or not this is a header. If not, of course, it s a footer.

PageNumbers

Object

Pointer to a PageNumbers collection that represents page number information in this header or footer. (See the next section.)

LinkToPrevious

Logical

Indicates whether this header or footer is the same as the corresponding header or footer in the previous section of the document.

Page numbering

Page numbers can appear anywhere in a document, but are normally placed in either headers or footers. Word offers a variety of formatting options for page numbers, from normal Arabic numerals to letters, Roman numerals, and even chapter numbering (like 1 1, 1 2, and so forth). You also have a choice about the position of the number. It can go in a header or a footer, and it can be aligned left, center, or right, or at either an inside or outside margin. The last two choices apply only when the document has different odd and even page headers and footers, of course. All of those choices come just from the Insert|Page Number dialog. If you edit the header or footer manually, you can place the page number anywhere you want within it.

Word s PageNumbers collection consists of individual PageNumber objects. Each represents one occurrence of a page number in either a header or a footer. PageNumber is quite simple. Its only significant property is Alignment, which indicates the horizontal position of the page number. Table 12 shows the possible values.

Table 12. Aligning page numbers. These constants are the available values for the Alignment property of PageNumber.

Constant

Value

Constant

Value

wdAlignPageNumberLeft

0

wdAlignPageNumberInside

3

wdAlignPageNumberCenter

1

wdAlignPageNumberOutside

4

wdAlignPageNumberRight

2

   

The PageNumbers collection is where all the action occurs. It has a number of properties that describe page numbering within the section. Table 13 shows the ones you re most likely to use.

To use chapter-type page numbering, the chapter numbers must be identifiable. Associating them with an outline level does that. (See the next section, "Organizing text with lists.")

Table 13. The PageNumbers collection. Each section of a document lets you restart page numbering and change the appearance of page numbers.

Property

Type

Description

NumberStyle

Numeric

The style to use for the page number. Check the Object Browser for additional choices.

wdCaptionNumberStyleArabic

0

wdCaptionNumberStyleUppercaseRoman

1

wdCaptionNumberStyleLowercaseRoman

2

wdCaptionNumberStyleUppercaseLetter

3

wdCaptionNumberStyleLowercaseLetter

4

wdCaptionNumberStyleHebrewLetter1

45

 

RestartNumberingAtSection

Logical

Indicates whether the page numbers start over at the beginning of this section.

StartingNumber

Numeric

The first page number for this section, if RestartNumberingAtSection is .T.

IncludeChapterNumber

Logical

Indicates whether chapter-type numbering is used. That is, should page numbers be in the format "chapter separator page" for example, 13 4.

HeadingLevelForChapter

Numeric

The outline to be used as the chapter number in the page number

ChapterPageSeparator

Numeric

The character to use between the chapter number and the page number, for chapter-type numbering.

wdSeparatorHyphen

0

wdSeparatorEmDash

3

wdSeparatorPeriod

1

wdSeparatorEnDash

4

wdSeparatorColon

2

 

 

 

ShowFirstPageNumber

Logical

Indicates whether the page number appears on the first page of the section.

This code centers the page number in the footer, using lowercase Roman numerals.

#DEFINE wdCaptionNumberStyleLowercaseRoman 2

#DEFINE wdAlignPageNumberCenter 1

WITH oWord.ActiveDocument.Sections[1].Footers[1].PageNumbers

.Add()

.NumberStyle = wdCaptionNumberStyleLowercaseRoman

ENDWITH

oWord.ActiveDocument.Sections[1].Footers[1].PageNumbers[1].Alignment = ;

wdAlignPageNumberCenter

 

Copyright 2000 by Tamar E. Granor and Della Martin All Rights Reserved



Microsoft Office Automation with Visual FoxPro
Microsoft Office Automation with Visual FoxPro
ISBN: 0965509303
EAN: 2147483647
Year: 2000
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net