【发布时间】:2012-06-19 11:07:57
【问题描述】:
我制作了一个 Word 插件,它允许用户单击按钮、选择文件名并保存为 pdf 文件。
但很多时候,用户会收到此错误: System.Runtime.InteropServices.COMException (0x80004005):(大致翻译自丹麦语:)文件被另一个程序或用户使用。
即使文件名不存在。
这是我的代码:
If dlgSaveAsPDF.ShowDialog = System.Windows.Forms.DialogResult.OK Then
With Globals.ThisAddIn.Application
.ActiveDocument.ExportAsFixedFormat(OutputFileName:= _
dlgSaveAsPDF.FileName, ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentWithMarkup, IncludeDocProps:=False, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False)
End With
System.Diagnostics.Process.Start(dlgSaveAsPDF.FileName)
End If
文件永远不会被保存。
【问题讨论】:
-
确定文件名有 pdf 扩展名,并且不保留其 doc(x) 扩展名?
标签: .net pdf ms-word com-interop word-automation