I have Publisher document with MailMerge records. My goal is to convert each page with each record to separate PDF document.
I have written this code. It generates PDF files with correct names, but for some reason PDFs contain only the second record from MailMerge.
Sub MailMerge()
Dim Lot As MailMergeDataField
Dim Price As MailMergeDataField
Dim Street As MailMergeDataField
Dim i As Long
Dim MainDoc As Document
Set MainDoc = ActiveDocument
With MainDoc
For i = 1 To .MailMerge.DataSource.RecordCount
With .MailMerge
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
Set Lot = .DataFields.Item("Lot")
Set Price = .DataFields.Item("Price")
Set Street = .DataFields.Item("Street")
ThisDocument.ExportAsFixedFormat pbFixedFormatTypePDF, Lot.Value & "-" & Street.Value & ".pdf"
End With
.Execute Pause:=False, Destination:=pbMergeToNewPublication
End With
Next i
End With
End Sub
I guess it needs a little change and everything will work fine, but I can't find out the solution.