【问题标题】:Save word document as PDF with a variable in the filepath?将word文档另存为PDF并在文件路径中使用变量?
【发布时间】:2017-06-29 07:58:53
【问题描述】:

我正在制作一个 word-macro,将 word 文档保存为 PDF,名称中有一个数组变量,代码现在看起来像这样:

Private Sub CommandButton2_Click()
    'SavePDF
     Dim i As Integer
     i = ActiveDocument.MailMerge.DataSource.ActiveRecord
     Debug.Print i
     ActiveDocument.SaveAs2 FileName:="C:\temp\PDFSaves\" & finalArray(0, i) & ".pdf"
End Sub

但它不起作用,有什么建议吗?

另外,如果我将它设置为保存到不存在的文件路径,它会创建它吗?我希望将副本保存为 PDF,而不是实际的 Word 文档,因为它是一个模板。

【问题讨论】:

    标签: vba file pdf ms-word


    【解决方案1】:

    您需要使用ExportAsFixedFormat

    ActiveDocument.ExportAsFixedFormat OutputFileName:="C:\temp\PDFSaves\" & finalArray(0, i) & ".pdf", ExportFormat:=wdExportFormatPDF
    

    【讨论】:

    • 谢谢,它有效。现在去看看能不能打开。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 1970-01-01
    相关资源
    最近更新 更多