[英]Saving Word document as PDF
這與將 Word 文檔轉換為 PDF 格式有關。
我的 Excel VBA 代碼出錯。
運行時錯誤“5”:無效的過程調用或參數
保存為 Word 文檔有效
objWord.ActiveDocument.SaveAs PathName & NewFileName & ".docx"
下面運行,但它創建了一個非常大的 PDF 文檔。
objWord.ActiveDocument.SaveAs2 Filename:=PathName & NewFileName & ".pdf", _
FileFormat:=wdFormatPDF
我在 Word 中錄制了一個宏,將文件另存為 PDF,並按照以下方式修改了生成的代碼。
objWord.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
PathName & NewFileName & ".pdf", _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
我正在使用 Excel VBA 使用 Word 文檔進行郵件合並,它工作正常並且能夠以 Word 格式保存單個文檔,但我需要將其保存為 PDF 格式。
試試這個代碼,它確實將它保存在與 word 文檔所在的文件夾相同的文件夾中,但它可以工作。
Private Sub Knop2_Click()
Dim directory As String
Dim enddirectory As String
directory = "C:\docs" ' The starting directory
enddirectory = "C:\pdf" 'einde
Dim fso, newFile, folder, files
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(directory)
Set files = folder.files
For Each file In files
Dim newName As String
newName = Replace(file.Path, ".doc", ".pdf")
newName = Replace(file.Path, ".docx", ".pdf")
Documents.Open FileName:=file.Path, _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
ActiveDocument.ExportAsFixedFormat OutputFileName:=newName, _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
ActiveDocument.Close
Next
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.