【问题标题】:VBA: Export Word Doc to PDF with a different file nameVBA:将 Word Doc 导出为具有不同文件名的 PDF
【发布时间】:2018-10-29 17:59:18
【问题描述】:

目前我正在使用下面的代码将单词 doc 保存到具有默认文件名的 PDF 中。我想更改它以便我可以修改 PDF 文件名。欣赏它!

代码:

Sub Silent_save_to_PDF()
'
' Silent Save_to_PDF Macro
'
    ActiveDocument.ExportAsFixedFormat OutputFileName:= _
        Replace(ActiveDocument.FullName, ".docx", ".pdf") , _
        ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
        wdExportOptimizeForPrint, Range:=wdExportAllDocument, Item:= _
        wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
        BitmapMissingFonts:=True, UseISO19005_1:=False
End Sub

【问题讨论】:

  • 嗨,要更改文件名,请更改任何字符串的“ActiveDocument.FullName”

标签: vba ms-word


【解决方案1】:

只需明确设置文件名。

Sub Silent_save_to_PDF()

    Dim extra_text As String
    Dim file_name As String

    extra_text = "123"
    file_name = ActiveDocument.Path & "\" & Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1) & extra_text & ".pdf"

    ActiveDocument.ExportAsFixedFormat OutputFileName:=file_name, _
    ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
    wdExportOptimizeForPrint, Range:=wdExportAllDocument, Item:= _
    wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=True, _
    CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
    BitmapMissingFonts:=True, UseISO19005_1:=False

End Sub

【讨论】:

  • 谢谢!这行得通。有什么办法可以保留文档的原始名称并在之后添加其他文本?例如,我想在每个文档的原始文件名后添加“123”。
  • 查看修订版以获得更通用的方式来完成您正在寻找的内容。
猜你喜欢
  • 1970-01-01
  • 2018-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-30
  • 2017-07-31
  • 2019-02-17
  • 1970-01-01
相关资源
最近更新 更多