Hi Gang,
I'm trying to automate the steps of doing a mail merge, update fields and then saving that merge to a number of PDFs. The file names of the PDFs are from the mail merge. The word doc is fairly big as it contains about 25 pages with lots of images.
The
VB code goes along and appears to work OK for a time, then I get the following error:
Run-time error '-2147467259 (80004005)
The export failed due to an unexpected error
Here is the code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub MakePDFs()
Dim FileName As String
Dim FirstRecord As Long
Dim LastRecord As Long
Dim Index As Integer
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord
LastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
For Index = FirstRecord To LastRecord
Selection.WholeStory
Selection.Fields.Update
Sleep (1000)
FileName = ActiveDocument.MailMerge.DataSource.DataFields.Ite m("PartNumber").Value + ".pdf"
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
ActiveDocument.Path & "\" + FileName _
, 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
Sleep (1000)
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Next Index
End Sub
Any help is much appreciated. THANKS!