HeaderFooter Object

         Properties                 

Sections collection (Section object)
HeadersFooters collection (HeaderFooter object)
Multiple objects

Represents a single header or footer. The HeaderFooter object is a member of the HeaderFooters collection. The HeaderFooters collection includes all headers and footers in the specified document section.

Using the HeaderFooter Object

Use Headers(index) or Footers(index), where index is one of the WdHeaderFooterIndex constants (wdHeaderFooterEvenPages, wdHeaderFooterFirstPage, or wdHeaderFooterPrimary), to return a single HeaderFooter object. The following example changes the text of both the primary header and the primary footer the first section of the active document.

With ActiveDocument.Sections(1)
    .Headers(wdHeaderFooterPrimary).Range.Text = "Header text"
    .Footers(wdHeaderFooterPrimary).Range.Text = "Footer text"
End With

You can also return a single HeaderFooter object by using the HeaderFooter property with a Selection object.

Note   You cannot add HeaderFooter objects to the HeaderFooters collection.

Remarks

Use the DifferentFirstPageHeaderFooter property with the PageSetup object to specify a different first page. The following example inserts text into the first page footer in the active document.

With ActiveDocument
    .PageSetup.DifferentFirstPageHeaderFooter = True
    .Sections(1).Footers(wdHeaderFooterFirstPage) _
        .Range.InsertBefore _
        "Written by Joe Smith"
End With

Use the OddAndEvenPagesHeaderFooter property with the PageSetup object to specify different odd and even page headers and footers. If the OddAndEvenPagesHeaderFooter property is True, you can return an odd header or footer by using wdHeaderFooterPrimary, and you can return an even header or footer by using wdHeaderFooterEvenPages.

Use the Add method with the PageNumbers object to add a page number to a header or footer. The following example adds page numbers to the primary footer the first section of the active document.

With ActiveDocument.Sections(1)
    .Footers(wdHeaderFooterPrimary).PageNumbers.Add
End With