Word 无法将文档保存为 PDF
我正在 VB.Net 中编写 Microsoft Word 插件,并且有一段代码调用函数将文档另存为 PDF (Office 2007)。
我使用两个函数:
Public Sub SaveLandscape_CallBack(ByVal Control As Office.IRibbonControl)
SaveEbook(True)
End Sub
并且
Public Sub SaveEbook(ByVal ForceLandscape As Boolean)
Try
Dim FilePath As String = Globals.ThisAddIn.Application.ActiveDocument.Path & "\" & Globals.ThisAddIn.Application.ActiveDocument.Name & ".ebook.pdf"
Try
Globals.ThisAddIn.Application.ActiveDocument.ExportAsFixedFormat(OutputFileName:=FilePath, ExportFormat:=Word.WdExportFormat.wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=Word.WdExportOptimizeFor.wdExportOptimizeForPrint, Range:=Word.WdExportRange.wdExportAllDocument, Item:=Word.WdExportItem.wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:=Word.WdExportCreateBookmarks.wdExportCreateHeadingBookmarks, DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=True)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Catch Ex As Exception
MsgBox(Ex.ToString)
End Try
我对第二个函数进行了很多修剪,这就是为什么有这个未使用的参数。
第一个功能与功能区按钮相关联。每次运行它时,ExportAsFixedFormat 都会返回一个错误,指出文件正在使用中,无论我使用什么名称。
有什么想法吗?
谢谢,
金融理财师。
I'm programming a Microsoft Word plugin in VB.Net, and I have a code that calls a function to save the document as PDF (Office 2007).
I use two functions:
Public Sub SaveLandscape_CallBack(ByVal Control As Office.IRibbonControl)
SaveEbook(True)
End Sub
And
Public Sub SaveEbook(ByVal ForceLandscape As Boolean)
Try
Dim FilePath As String = Globals.ThisAddIn.Application.ActiveDocument.Path & "\" & Globals.ThisAddIn.Application.ActiveDocument.Name & ".ebook.pdf"
Try
Globals.ThisAddIn.Application.ActiveDocument.ExportAsFixedFormat(OutputFileName:=FilePath, ExportFormat:=Word.WdExportFormat.wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=Word.WdExportOptimizeFor.wdExportOptimizeForPrint, Range:=Word.WdExportRange.wdExportAllDocument, Item:=Word.WdExportItem.wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:=Word.WdExportCreateBookmarks.wdExportCreateHeadingBookmarks, DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=True)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Catch Ex As Exception
MsgBox(Ex.ToString)
End Try
I've trimmed the second one a lot, which is why there is this unused parameter.
The first function is associated to a ribbon button. Every time I run it, ExportAsFixedFormat returns an error saying the file is in use, whatever name I use.
Any idea?
Thanks,
CFP.
EDIT: I've identified the problem to be exactly the same as http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/95c5b101-0d98-49f8-a92b-7b444e61cca8/ . Any ideas anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将
Globals.ThisAddIn.Application.ActiveDocument.Saved = True
放在Globals...
行之前。Try putting
Globals.ThisAddIn.Application.ActiveDocument.Saved = True
before theGlobals...
line.