Hello,
I am working on a project in which a mail merge document will ultimately generate several PDF documents (1 PDF per Merge Record). The PDF document itself is saved with a file name based on a merge field on the master merge document. The problem I am having is finding a way to loop through to the next merge record and repeat until all merge records have generated their own PDF.
I am using the code below as a starting point:
Code:
Sub Macro1()
'
' Macro1 Macro
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
.LastRecord = ActiveDocument.MailMerge.DataSource.LastRecord
End With
.Execute Pause:=False
End With
ActiveWindow.ActivePane.VerticalPercentScrolled = 64
Selection.WholeStory
Selection.Fields.Update
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"Q:\FILE PATH\" & _
Documents("MasterTemplate.doc").MailMerge.DataSource.DataFields("File_Name").Value & ".pdf", ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, FROM:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
ActiveWindow.Close
End Sub
I am working in Word 2007 and I know there are ways to merge to individual documents built in, however, I need to use the code as there is an image that is generated based on a merge field. This requires that the individual record be updated using Selection.WholeStory and Selection.Fields.Update
If anyone knows how to get this code to repeat (it works PERFECT for the first record) for each record that would be swell!
Thanks!