1
votes

I'm trying to write some excel vba to change the position of a header/footer in a word document. The item I want to change using VBA is "Header from Top".

I can't find any solutions - even when I record a word macro and change the position then the macro is blank.

Any ideas?

1
What do you mean by position of a header/footer in a word document. Do you mean the contents of the top header? - Siddharth Rout
I mean the position of the header itself. In Word you can specify "Header from Top" and "Footer from Bottom" which default to 1.25cm. So the header is 1.25cm from top of page (different to margin). I can change margins with vba no prob but cant seem to change the header position. - Kyo

1 Answers

0
votes

I can't find any solutions - even when I record a word macro and change the position then the macro is blank.

I could easily record a macro in VBA Word. This is what I got

Sub Macro2()
'
' Macro2 Macro
'
'
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
        ActivePane.View.Type = wdOutlineView Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    With Selection.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = InchesToPoints(1)
        .BottomMargin = InchesToPoints(1)
        .LeftMargin = InchesToPoints(1)
        .RightMargin = InchesToPoints(1)
        .Gutter = InchesToPoints(0)
        .HeaderDistance = InchesToPoints(0.7)
        .FooterDistance = InchesToPoints(0.5)
        .PageWidth = InchesToPoints(8.5)
        .PageHeight = InchesToPoints(11)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft
    End With
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

What you actually want is .HeaderDistance = InchesToPoints()