none
OOXML merging two documents with different header and footer settings with an alternate content in the header/footer RRS feed

  • Question

  • In our mail merge software we have the ability to merge multiple documents into one output document. In the final document we need to maintain the header and footer settings for each of the sections. In Word 2003/2007 our algorithm works for drawing and text, but in 2010 our algorithm breaks for alternate content but works for text.

    When we merge we check to see if even and odd headers are enabled, if they are not then we need to setup the appropriate relationships and settings in the document. Is there a new relationship that was added to 2010 for alternate content being in the footer that is causing the document to come out corrupted on load?

    Tuesday, May 22, 2012 8:54 PM

Answers

  • I got more into this issue and found that the drawing elements in 2010 contain an ID, this ID must be unique within a document. And so my solution was to just find all these IDs and map them all to unique ones, and the document now successfully opens.

    <mc:AlternateContent>
      <mc:Choice Requires="wpg">
        <w:drawing>
          <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251659264" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="238E07E9" wp14:editId="0D74856F">
            <wp:docPr id="444" name="Group 2"/>
    This is not just an issue with the headers and footers, this is across the whole document.
    Friday, May 25, 2012 12:14 PM

All replies

  • Hi NathanWCF,

    Welcome to the MSDN forum!

    As far as I know, footers and headers can be different for odd and even pages. The following code provides an example.

    Public Sub MakeFooters()
        Const vbTap As String = "    "
        Dim oRange As Range
        Dim oSection As Section
        Dim sFooter As String
        
        For Each oSection In ThisDocument.Sections
            ' Different odd and even page headers
            oSection.PageSetup.OddAndEvenPagesHeaderFooter = True
            
            ' Unlink the headers and add a top stop at the right margin
            With oSection.Footers(wdHeaderFooterPrimary)
                .LinkToPrevious = False
                .Range.ParagraphFormat.TabStops.ClearAll
                .Range.ParagraphFormat.TabStops.Add _
                    oSection.PageSetup.PageWidth - oSection.PageSetup.RightMargin - oSection.PageSetup.LeftMargin, _
                    WdTabAlignment.wdAlignTabRight
            End With
            
            ' Repeat for even page header
            With oSection.Footers(wdHeaderFooterEvenPages)
                .LinkToPrevious = False
                .Range.ParagraphFormat.TabStops.ClearAll
                .Range.ParagraphFormat.TabStops.Add _
                    oSection.PageSetup.PageWidth - oSection.PageSetup.RightMargin - oSection.PageSetup.LeftMargin, _
                    WdTabAlignment.wdAlignTabRight
            End With
            
            sFooter = "Footer - This is a test."
           
            
            ' Do odd-page (primary header)
            Set oRange = oSection.Footers(wdHeaderFooterPrimary).Range
            oRange.Text = sFooter & vbCrLf & "page "
            
            oRange.Collapse wdCollapseEnd
            
            ' Insert page number
            oRange.Fields.Add oRange, WdFieldType.wdFieldPage
       
            Set oRange = oSection.Footers(wdHeaderFooterEvenPages).Range
            oRange.Collapse wdCollapseEnd
            oRange.InsertAfter vbTab & sFooter
            
        Next oSection
    End Sub

    You can set footers for different sections.

    Reference from: http://www.bettersolutions.com/word/WZK193/VV927866882.htm 

    Meanwhile, for using word issue, you can ask questions in the answers forum:

    Answers - Word

    http://answers.microsoft.com/en-us/office/forum/word

    Thanks.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Friday, May 25, 2012 7:36 AM
    Moderator
  • I got more into this issue and found that the drawing elements in 2010 contain an ID, this ID must be unique within a document. And so my solution was to just find all these IDs and map them all to unique ones, and the document now successfully opens.

    <mc:AlternateContent>
      <mc:Choice Requires="wpg">
        <w:drawing>
          <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251659264" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="238E07E9" wp14:editId="0D74856F">
            <wp:docPr id="444" name="Group 2"/>
    This is not just an issue with the headers and footers, this is across the whole document.
    Friday, May 25, 2012 12:14 PM