![]() |
#2
|
||||
|
||||
![]()
Word's built-in mailmerge tools will allow you to create a single document containing all 5 pages for each record. To create a separate file for each record, you'll need a macro.
The following macro generates one output file per record. Files are saved to the same folder as the mailmerge main document, using the ‘Last_Name’ & ‘First_Name’ fields in the data source for the filenames. PDF & DOCX formats are catered for. Code:
Sub Merge_To_Individual_Files() 'Merges one record at a time to the chosen output folder Application.ScreenUpdating = False Dim StrFolder As String, StrName As String, MainDoc As Document, i As Long, j as long Set MainDoc = ActiveDocument With MainDoc StrFolder = .Path & Application.PathSeparator For i = 1 To .MailMerge.DataSource.RecordCount With .MailMerge .Destination = wdSendToNewDocument .SuppressBlankLines = True With .DataSource .FirstRecord = i .LastRecord = i .ActiveRecord = i If Trim(.DataFields("Last_Name")) = "" Then Exit For StrName = .DataFields("Last_Name") & "_" & .DataFields("First_Name") End With .Execute Pause:=False End With StrName = Trim(StrName) With ActiveDocument .SaveAs2 FileName:=StrPath & StrName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False ' and/or: .SaveAs2 FileName:=StrPath & StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False .Close SaveChanges:=False End With Next i End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Dart82 | Word | 4 | 05-06-2014 11:23 PM |
Multiple records on the same page | Hugh | Mail Merge | 2 | 04-04-2014 05:24 PM |
2 page document printing problem, text from page 1 in layout of page 2 when printed | laurawether45 | Word | 1 | 08-02-2012 07:03 AM |
Consecutive page numbers on multiple documents | georgeeasten | Word | 1 | 02-10-2011 02:12 AM |
![]() |
reitdesign | Word | 3 | 12-12-2008 11:55 AM |