WORD 2010 Macro for Editing Headers & Footers

前端 未结 2 1161
时光说笑
时光说笑 2021-02-09 04:05

I have only basic VBA experince and my prior Macro experence was primarily with WORD 2003. Recording Macros used to take GoToFooter (or Edit Footer) Menu Commands and allow sub

相关标签:
2条回答
  • 2021-02-09 04:44

    Here is a way you can access the headers/footers via VBA. As you can see, it's rather complicated syntax to get to something so simple :p there

    Sub EditHeadersAndFooters()
    
    Dim i As Long
    
    For i = 1 To ActiveDocument.Sections.Count
        With ActiveDocument.Sections(i)
            .Headers(wdHeaderFooterPrimary).Range.Text = "Foo"
            .Footers(wdHeaderFooterPrimary).Range.Text = "Bar"
        End With
    Next
    
    End Sub
    

    Here is a link to example code on how to change the headers in every file in a folder. It takes a different approach and I have never tried it, but for your reference: http://www.vbaexpress.com/kb/getarticle.php?kb_id=45

    0 讨论(0)
  • 2021-02-09 05:04

    This worked for me for all pages in the document.

    word.ActiveDocument.Sections(1).Headers(1).Range.Text = "Put the header here"

    0 讨论(0)
提交回复
热议问题