I am trying to add a header and a footer to each page of a word document via a macro.
I have tried a few different methods such as iterating through each shape on the page but in that case , the header and footer prints out multiple times on each page depending on how many shapes are in the document.
Currently my code is looking for any current header and footer and deleting them, then it just inserts my header and footer on the first page and leaves the remaining pages in the document's header and footer blank.
Can anyone tell me where I am going wrong?
Sub HeaderFooter()
Dim oSec As Section
Dim oHead As HeaderFooter
Dim oFoot As HeaderFooter
For Each oSec In ActiveDocument.Sections
For Each oHead In oSec.Headers
If oHead.Exists Then oHead.Range.Delete
Next oHead
For Each oFoot In oSec.Footers
If oFoot.Exists Then oFoot.Range.Delete
Next oFoot
Next oSec
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Selection.PageSetup
.HeaderDistance = CentimetersToPoints(1.0)
.FooterDistance = CentimetersToPoints(1.0)
End With
Selection.InlineShapes.AddPicture FileName:="image.jpg" _
, LinkToFile:=False, SaveWithDocument:=True
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.Font.Color = RGB(179, 131, 89)
Selection.Font.Size = 10
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.TypeText Text:="footer test"
End Sub