word vba文档另存为PDF,可选择保存路径
时间: 2023-09-25 10:10:07 浏览: 183
以下是将 Word VBA 文档另存为 PDF 并选择保存路径的示例代码:
```
Sub SaveAsPDF()
Dim savePath As String
'选择保存路径
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "选择保存路径"
.Show
If .SelectedItems.Count = 0 Then Exit Sub
savePath = .SelectedItems(1)
End With
'另存为PDF
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
savePath & "\" & ActiveDocument.Name & ".pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, _
KeepIRM:=True, _
CreateBookmarks:= _
wdExportCreateNoBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=False
End Sub
```
首先,我们通过 `Application.FileDialog` 对象选择保存路径,然后使用 `ActiveDocument.ExportAsFixedFormat` 方法将文档另存为 PDF。在 `OutputFileName` 参数中,我们指定了文件名及保存路径。
阅读全文