Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2009

    Unanswered: Word 2007: getting Run time error -2147467259 (80004005) while saving as a PDF

    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

    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!

  2. #2
    Join Date
    Jun 2009


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts