View Single Post
 
Old 09-15-2020, 01:54 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 of
Default

There would be nothing 'automatic' about it, but you could certainly create a document containing a table with merge fields and then using that document to replace a similar table in a batch of documents. The main issue is that of identifying the table to be replaced, especially if there is more than one table in the document.

Assuming that the tables have no merged or split cells, the following custom process used in conjunction with Document Batch Processes will replace the first matching table in the batch of documents with the table in your sample document with the fields.
Code:
Sub ChangeTable(oTarget As Document)
Dim oSource As Document
Dim oTable1 As Table, oTable2 As Table
Dim oRng As Range, oRng1 As Range
    'Change path to reflect the location of the source document
    Set oSource = Documents.Open(Environ("USERPROFILE") & "\Desktop\TableSource.docx")
    oSource.MailMerge.MainDocumentType = wdNotAMergeDocument
    Set oTable1 = oSource.Tables(1)
    Set oRng1 = oTable1.Range
    oRng1.End = oRng1.End + 1
    For Each oTable2 In oTarget.Tables
        If oTable2.Rows.Count = oTable1.Rows.Count And _
           oTable2.Columns.Count = oTable1.Columns.Count Then
            Set oRng = oTable2.Range
            oRng.End = oRng.End + 1
            oRng.Text = ""
            oRng.FormattedText = oRng1.FormattedText
            Exit For
        End If
        DoEvents
    Next oTable2
lbl_Exit:
    Set oSource = Nothing
    Set oTarget = Nothing
    Set oTable1 = Nothing
    Set oTable2 = Nothing
    Set oRng = Nothing
    Set oRng1 = Nothing
    Exit Sub
End Sub
Do you actually need 100 mail merge documents? In what way do those documents differ from one another?
__________________
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