Share via

Failure when coding ActiveDocument.ExportAsFixedFormat in Word 2010

Anonymous
2016-06-10T02:42:49+00:00

To properly work, I need to have the document requiring conversion open and active prior to running the export.

Intermittently, the export will fail with message "Runtime error 2147467259 (800004005) This file is in use by another application or user."

After a lot of experimenting, it appears the file it is complaining about is the Document I am trying to export (The active document) although it is very hard to be certain of this.  The OutputFileName: is always the same, but I don't know whether it is this file it intermittently complains of.  It appears the Export is quite happy to overwrite this file most times. Here is vba Code

:[

    Documents.Open FileName:="C:\Users\Public@@@@@@@\Documents\1212\CP+~1212~0000007000~XRETL~685722B.docx"

    ActiveDocument.ExportAsFixedFormat OutputFileName:= _

        "C:\Users\Public@@@@@@@\PDF\CP+~1212~0000007000~XRETL~685722B.pdf" _

        , ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _

        wdExportOptimizeForOnScreen, Range:=wdExportAllDocument, From:=1, To:=1, _

        Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _

        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=False, _

        BitmapMissingFonts:=False, UseISO19005_1:=False

    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

]

Any advice much appreciated.

Ian B

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2016-06-10T06:01:24+00:00

The code will fail in that manner if the output file is open in Adobe Reader.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2016-06-10T23:20:24+00:00

    Thank you for your reply Doug.  Although it wasn't actually the problem, it gave me the clue to work around and eliminate the problem.  The failing macro had a parameter of "OpenAfterExport:=False" so there was no visible sign of the exported file being opened. I then uninstalled Adobe Reader.   The problem remained.  As a long shot, I changed the extension on the exported file from .pdf to ,pdaf and the problem disappeared. 

    I can only assume that  when a .pdf was created, Adobe behind the scenes, invisibly grabbed ownership of the file such that it could not be overwritten or deleted.  I  reinstalled Adobe, reverted to .pdf and the problem did not return.

    I cannot provide a better explanation, and as the problem has gone, cannot investigate it further.

    Thanks again for your response!

    Ian B

    Was this answer helpful?

    0 comments No comments