VBA: экспорт Word Doc в PDF с другим именем - PullRequest
0 голосов
/ 29 октября 2018

В настоящее время я использую приведенный ниже код, который сохраняет слово 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

1 Ответ

0 голосов
/ 29 октября 2018

Просто установите имя файла явно.

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
...