How do I identify the section of a range of text, and then copy the footer of the next section to the current section? RRS feed

  • Question

  • I am working on a large report (795 pages) with 652 sections. The report is split into chapters with each chapter having a separator page with a picture covering the footer. The original authors did not update the footers under the picture, with the result that the first page of the chapter has the same footer as the previous chapter, although not visible. I want to select the text in the page, determine the section that it belongs to and copy the footer from the section that follows it.  It is important for updating content in the document (652 Tables, 365 shapes) from excel as the footer is the key to the excel named ranges.

    The challenge I'm having is identifying the section that a selected range belongs to, to be able to access the footer.

    Any help would be appreciated.



    Tuesday, April 15, 2014 2:21 PM


  • Hi Riaan

    The first step would be making sure that all the footers are unlinked, so that they aren't "inheriting" the information from the previous one. Have you done that already, or does the macro need to do that, as well?

    Here's code that performs the actions you request

    Sub TransferNextSecFooter()
        Dim rngCurSec As word.Range
        Dim rngNextSecFooter As word.Range
        Dim curSec As Long
        Set rngCurSec = Selection.Range
        curSec = rngCurSec.Sections(1).index
        Set rngNextSecFooter = ActiveDocument.Sections(curSec + 1).Footers(wdHeaderFooterPrimary).Range
        ActiveDocument.Sections(curSec).Footers(wdHeaderFooterPrimary).Range.FormattedText _
           = rngNextSecFooter.FormattedText
    End Sub

    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, April 15, 2014 4:18 PM