View Single Post
 
Old 03-25-2015, 08:04 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The reason that the field in the footer does not update is that the merge process changes the filename field that you are trying to update into plain text. It would therefore be better if you removed the filename field from the merge document, and then add it after the merge e.g. call the following macro to add the field to the merged document after you have saved it (and note that it will need to be saved again).

Code:
Sub AddFilename()
Dim oSection As Section
Dim oFooter As HeaderFooter
Dim oFld As field
Dim bFound As Boolean
Dim oRng As Range
    For Each oSection In ActiveDocument.Sections
        Set oFooter = oSection.Footers(wdHeaderFooterPrimary)
        For Each oFld In oFooter.Range.Fields
            If oFld.Type = wdFieldFileName Then
                bFound = True
                Exit For
            End If
        Next oFld
        If Not bFound Then
            oFooter.Range.InsertParagraphAfter
            Set oRng = oFooter.Range.Paragraphs.Last.Range
            oRng.ParagraphFormat.Alignment = wdAlignParagraphRight
            oRng.Fields.Add oRng, wdFieldFileName, " \p", False
            oRng.Fields.Update
        End If
    Next oSection
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote