Class HeaderFooter (Word VBA)

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

Set

To use a HeaderFooter class variable it first needs to be instantiated, for example

Dim hfr as HeaderFooter
Set hfr = Selection.HeaderFooter

The following procedures can be used to set variables of type HeaderFooter: HeadersFooters.Item, Selection.HeaderFooter, Section.Footers and Section.Headers

For Each

Here is an example of processing the HeaderFooter items in a collection.

Dim hfrFooter As HeaderFooter
For Each hfrFooter In Footers
	
Next hfrFooter

Properties

Exists true if the specified HeaderFooter object exists.

Selection.HeaderFooter.Exists = True

Index returns a WdHeaderFooterIndex that represents the specified header or footer in a document or section.

Dim whfIndex As WdHeaderFooterIndex
whfIndex = Selection.HeaderFooter.Index

IsEmpty

Dim booIsEmpty As Boolean
booIsEmpty = Selection.HeaderFooter.IsEmpty

IsHeader true if the specified HeaderFooter object is a header.

Dim booIsHeader As Boolean
booIsHeader = Selection.HeaderFooter.IsHeader

LinkToPrevious true if the specified header or footer is linked to the corresponding header or footer in the previous section.

Selection.HeaderFooter.LinkToPrevious = True

PageNumbers returns a PageNumbers collection that represents all the page number fields included in the specified header or footer.

Dim pnsPageNumbers As PageNumbers
Set pnsPageNumbers = Selection.HeaderFooter.PageNumbers

Parent returns an object that represents the parent object of the specified HeaderFooter object.

Dim objParent As Object
Set objParent = Selection.HeaderFooter.Parent

Range returns a Range object that represents the portion of a document that is contained within the specified header or footer.

Dim rngRange As Range
Set rngRange = Selection.HeaderFooter.Range

Shapes returns a Shapes collection that represents all the Shape objects in a header or footer.

Dim shpsShapes As Shapes
Set shpsShapes = Selection.HeaderFooter.Shapes

HeadersFooters.Count returns a Long that represents the number of headers and/or footers in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.Range.Sections(1).Headers.Count

HeadersFooters.Parent returns an object that represents the parent object of the specified HeadersFooters object.

Dim objParent As Object
Set objParent = ActiveDocument.Range.Sections(1).Headers.Parent