Headers & Footers


HeaderFooter object

A HeaderFooter object represents either a single header or footer.
The headerfooter object can represent either a header or footer. This object is available from the Selection obect
A HeaderFooters collection contain HeaderFooter objects of one type (header or footer).
The HeadersFooters collection includes all headers and footers in the specified document section.


A HeaderFooter collection, whether it be a collection of headers or a collection of footers is indexed by one of the constants in the following enumeration.


wdInformation.wdInHeaderFooter 
wdInformation.wdHeaderFooterType

There are three different types of headers and three types of footers
Primary
First Page
Even Pages


Primary

To obtain the HeaderFooter object that represents the primary header in the first section of the active document

Dim objHeaderFooter As HeaderFooter 
objHeaderFooter = ActiveDocument.Sections(1).Headers wdHeaderFooterIndex.wdHeaderFooterPrimary

objHeaderFooter = ActiveDocument.Sections(1).Footers wdHeaderFooterIndex.wdHeaderFooterPrimary 

The following code changes the text in both the primary header and the primary footer

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


Current Selection

Note that if the current selection is within a header or footer then the HeaderFooter property of the Selection object will return the active HeaderFooter object.

objHeaderFooter = Selection.HeaderFooter 


Activating

ActiveWindow.ActivePane.View.SeekView = wdSeekView.wdSeekCurrentPageHeader 
ActiveWindow.ActivePane.View.SeekView = wdSeekView.wdSeekCurrentPageFooter


Deactivating

ActiveWindow.ActivePane.View.SeekView = wdSeekView.wdSeekMainDocument 


Modifying ??

With ActiveDocument.Sections(1).Footers(wdHeaderFooterIndex.wdHeaderFooterPrimary) 
   .Delete
   .Fields.Add range := Selection, type := wdfieldname, text := "\p"
   .InsertAfter text := vbTab
   .InsertAfter text := vbTab
   .Collapse direction := wdCollapseDirection.wdCollapseStart
   .Fields.Add range := Selection, type := fieldauthor
End With


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext