Word 无法将文档保存为 PDF

发布于 2024-09-19 09:38:33 字数 1622 浏览 7 评论 0原文

我正在 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 都会返回一个错误,指出文件正在使用中,无论我使用什么名称。

有什么想法吗?

谢谢,
金融理财师。

编辑:我发现问题与http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/95c5b101-0d98-49f8-a92b-7b444e61cca8/。有人有什么想法吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜声 2024-09-26 09:38:33

尝试将 Globals.ThisAddIn.Application.ActiveDocument.Saved = True 放在 Globals... 行之前。

Try putting Globals.ThisAddIn.Application.ActiveDocument.Saved = True before the Globals... line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文