【问题标题】:MS Word ExportAsFixedFormat(..) throws Exception 80070057MS Word ExportAsFixedFormat(..) 抛出异常 80070057
【发布时间】:2018-07-29 19:59:25
【问题描述】:

我想在 Microsoft Word 中自动执行 print2PDF 程序,以便与 Dragon NaturallySpeaking 一起使用。

我创建了这个宏,当用户打开一个文档并说“打印到 PDF”时执行它:

Sub Main
    'On Error GoTo errorHandler

    Set wApp = GetObject(,"Word.Application")

    If wApp.Documents.Count >= 1 Then
        wApp.ActiveDocument.ExportAsFixedFormat OutputFileName :="tst1.pdf", _
        ExportFormat := wdExportFormatPDF, _
        UseISO19005_1 := True
    Else
        MsgBox "Kein Dokument geöffnet"
    End If
    Set wApp = Nothing

    Exit Sub

    errorHandler:
    MsgBox "Ein Fehler ist aufgetreten. Kontaktieren Sie Helpdesk."
    Set wApp = Nothing
End Sub

但是在执行时我总是得到错误 80070057。我用谷歌搜索了错误代码,它说“无效的争论”,但我无法解释这一点,因为我一直在遵循这个 MSDN 链接中的步骤:https://msdn.microsoft.com/de-de/VBA/Word-VBA/articles/document-exportasfixedformat-method-word 到信件。你知道我可以尝试什么来克服这个错误吗?

我尝试过的解决方法: 使用 SaveAs 和 SaveAs2 也不起作用,它们总是忽略我需要的格式 (wdFormatPDF) 并将文档另存为 docx。唯一有效的方法是将 ActivePrinter 设置为 print2pdf,然后使用 PrinOut 方法,但它给了我一个我不想要的打印机对话框。

【问题讨论】:

  • 您能否以用户身份保存为 PDF - 该功能在您的安装中是否真正起作用?哪个版本的 Word?
  • 我可以使用 File->Save As-> filename.pdf 将 word coument 保存为 PDF,是的。
  • 我们使用的是 Office 2016
  • 两个想法: 1) 提供带有文件名的完整路径 OutputFilename ; 2)尝试完全删除最后一个参数,因为它是可选的。但我怀疑它很可能是文件路径...

标签: vba ms-word


【解决方案1】:

这个问题很可能是由于您使用带有命名参数的后期绑定(这需要早期绑定)引起的。而不是:

wApp.ActiveDocument.ExportAsFixedFormat OutputFileName :="tst1.pdf", _ ExportFormat := wdExportFormatPDF, UseISO19005_1 := True

尝试:

wApp.ActiveDocument.ExportAsFixedFormat "tst1.pdf", 17, , , , , , , , , , , , True

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 2013-05-24
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    相关资源
    最近更新 更多