Mail Merge End of File

  • Thread starter Frustrated Mail Merger
  • Start date
F

Frustrated Mail Merger

I am trying to do a mail merge into two separate tables in the same document.
However, when it gets done merging the first table it of course is at the
end of file. Then when it gets to the second table in the document - it
doesn't merge anything because it's at the end of file. How do I get it to
go back to the beginning of the file before it starts merging into the second
table?
 
D

Doug Robbins - Word MVP

Just how do you have the mergefields arranged in the mailmerge main
document? The data should repeat for each instance of the mergefields in
the main document.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
F

Frustrated Mail Merger

The table on page 1 has 7 columns and many rows. I have the fields placed in
the 1st row and then at the beginning of the 2nd row I have Next Record in
the first cell and then the fields placed like row 1. The rest of the rows
are all like row 2 with Next Record in cell 1. Then on page 5 of the same
document I have another table with different information - it has 11 columns
and many rows. Again I have row 1 with the data I want placed and then on
the rest of the rows I have Next Record in cell 1 and the same data placed.
The first table works fine - but it doesn't go back to the beginning of the
file for the table on page 5 (this table is blank).
 
D

Doug Robbins - Word MVP

The only way to handle that will be to use two mailmerge maindocuments and
execute the merges to new documents and then to combine them back into one.
The following macro that was written for a person who wanted to create a
document made up by interleaving the pages from two separate documents,
could be modified to handle the combination of the two mail merge documents.

Dim sourcea As Document, sourceb As Document, target As Document, Pages
As Integer, Counter As Integer, targetrange As Range 'targetrange added

Dim evenpage As Range

Set sourcea = Documents.Open(FileName:="...")

sourcea.Repaginate

Pages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)

MsgBox Pages

Set sourceb = Documents.Open(FileName:="...")

Set target = Documents.Add

target.PageSetup.LeftMargin = sourcea.PageSetup.LeftMargin

target.PageSetup.RightMargin = sourcea.PageSetup.RightMargin

target.PageSetup.TopMargin = sourcea.PageSetup.TopMargin

target.PageSetup.BottomMargin = sourcea.PageSetup.BottomMargin

target.AcceptAllRevisions

Counter = 0

While Counter < Pages

sourcea.Activate

ActiveDocument.Bookmarks("\page").Range.Copy

Set targetrange = target.Range

targetrange.Start = targetrange.End

targetrange.Paste

ActiveDocument.Bookmarks("\page").Range.Cut

sourceb.Activate 'Assumed to be the document containing the even
pages

Selection.EndKey Unit:=wdStory 'Line of code added to start from the
end of the document

ActiveDocument.Bookmarks("\page").Range.Copy

Set targetrange = target.Range

targetrange.Start = targetrange.End

targetrange.Paste

targetrange.Start = targetrange.End

targetrange.InsertBreak Type:=wdPageBreak

Set evenpage = ActiveDocument.Bookmarks("\page").Range

evenpage.Start = evenpage.Start - 1

evenpage.Delete

Counter = Counter + 1

Wend

sourcea.Close wdDoNotSaveChanges

sourceb.Close wdDoNotSaveChanges

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top