word vba文档另存为PDF
时间: 2023-07-24 09:23:09 浏览: 237
你可以使用以下VBA代码将Word文档另存为PDF:
```
Sub SaveAsPDF()
' 定义变量
Dim filePath As String
Dim fileName As String
' 获取文件路径和文件名
filePath = "C:\Users\UserName\Documents\"
fileName = ActiveDocument.Name
fileName = Left(fileName, InStrRev(fileName, ".") - 1) & ".pdf"
' 另存为PDF
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
filePath & fileName, 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
End Sub
```
在代码中,你需要替换 `filePath` 变量为你想要保存PDF的文件夹路径,然后运行 `SaveAsPDF` 子过程即可将当前Word文档另存为PDF。
阅读全文