A family of Microsoft word processing software products for creating web, email, and print documents.
The code will fail in that manner if the output file is open in Adobe Reader.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
A family of Microsoft word processing software products for creating web, email, and print documents.
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.
Answer accepted by question author
The code will fail in that manner if the output file is open in Adobe Reader.
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