A HeaderFooter object represents either a header or a footer. A HeadersFooters collection contains HeaderFooter objects of one type (header or footer) or the other, but not both.
A HeadersFooters collection, whether it be a collection of headers or footers, is indexed by one of the constants in the following enum:
Enum WdHeaderFooterIndex wdHeaderFooterPrimary = 1 wdHeaderFooterFirstPage = 2 wdHeaderFooterEvenPages = 3 End Enum
As you can see, there are three types of headers and three types of footers. (I discuss the meaning of a primary header or footer a bit later in this chapter.)
Thus, to obtain the HeaderFooter object that represents the primary header in the first section of the active document, write:
Similarly, the primary footer in this section is:
As an example, the following code changes the text in both the primary header and the primary footer:
With ActiveDocument.Sections(1) .Headers(wdHeaderFooterPrimary).Range.Text = "Header text" .Footers(wdHeaderFooterPrimary).Range.Text = _ "Footer text" End With
Note that if the current selection is within a header or footer, the HeaderFooter property of the Selection object will return that HeaderFooter object.
The PageSetup object has two properties that relate to headers and footers: DifferentFirstPageHeaderFooter and OddAndEvenPagesHeaderFooter.
You can ...