![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
|
|
#1
|
|||
|
|||
|
I have about 100 documents that I am going to make into mailmerge documents. Each document has an identical table where I am going to insert merge fields. I would like to create one document that contains only the table complete with mailmerge fields and then have that document be automatically inserted into each of the 100 documents when they are loaded for mailmerge. This would mean that I have to create the mailmerge fields for the table only once instead of 100 times. Can do?
|
|
#2
|
|||
|
|||
|
Maybe this link can resolve your issue:- https://www.msofficeforums.com/word-...documents.html
|
|
#3
|
||||
|
||||
|
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
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#4
|
|||
|
|||
|
You could also save your table as AutoText or a QuickTable and then manually insert into the appropriate templates.
I join Graham's question as to the need for all those primary merge documents. |
|
| Tags |
| mailmerge |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |