VBA word to edit the header/footer for the active page

MrDavidThorn used Ask the Experts™
Hi Experts

I have a word document  - page 1 and 3 are in potrait and page 2 is in landsacape - the document contains headers and footers, each header and footer has a table inside, when I switch to the landscape page the header and the footers table margins are incorrect, Im looking for the VBA code to amend these tables for a given page number, how can I do this?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
Addressing by page is normally not done in Word because re-pagination can affect what is on any particular page. In this case page 2 is in landscape between two portrait-orientated pages, so it must be in its own section.

It isn't clear why you need VBA.
Make sure that the header and the footer are not linked to page1, and adjust the table manually. If you do need code, then you can start with this.
Sub HeaderTable()
    Dim tbl As Table
    Dim hdr As HeaderFooter
    hdr.LinkToPrevious = False
    Set hdr = ActiveDocument.Sections(2).Headers(wdHeaderFooterPrimary)
    Set tbl = hdr.Range.Tables(1)
    tbl.Rows(1).HeightRule = wdRowHeightExactly
    tbl.Rows(1).Height = CentimetersToPoints(1)
End Sub

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial