Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-15-2020, 01:54 AM
gmayor's Avatar
gmayor gmayor is offline 100 Primary Mail Merge Documents - want to add a table with fields to all of the primary documents Windows 10 100 Primary Mail Merge Documents - want to add a table with fields to all of the primary documents Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
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

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
Reply

Tags
mailmerge



Similar Threads
Thread Thread Starter Forum Replies Last Post
100 Primary Mail Merge Documents - want to add a table with fields to all of the primary documents Primary Command Buttons (along top of window) Disappeared Andrew H Word 8 01-04-2018 06:48 AM
Primary color theme in PowerPoint broiling PowerPoint 0 10-03-2017 01:02 AM
Mail Merge - Word primary, Excel secondary - track changes marking voyagerone Mail Merge 9 06-30-2017 08:55 PM
After Mail merging single documents - how to combine several documents into one? Abacus1234 Mail Merge 16 06-25-2015 06:56 AM
Two Primary calendars?!?!? Outlook 2013 countersteer Outlook 0 03-30-2014 06:38 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:41 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft