Word VBA另存为PDF,可选储存位置
时间: 2024-01-16 19:05:19 浏览: 208
Word另存为PDF
5星 · 资源好评率100%
可以使用以下代码来实现:
```
Sub SaveAsPDF()
Dim FilePath As String
Dim FileName As String
'获取文件名和路径
FilePath = Application.ActiveDocument.Path
FileName = Application.ActiveDocument.Name
FileName = Left(FileName, InStrRev(FileName, ".") - 1)
'设置文件保存路径
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "请选择文件保存的文件夹"
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub
FilePath = .SelectedItems(1) & "\"
End With
'保存PDF文件
Application.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
FilePath & FileName & ".pdf", _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, _
OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
End Sub
```
在执行该宏时,会弹出一个文件夹选择对话框,让用户选择保存文件的文件夹。然后,程序会将当前文档另存为PDF文件并保存到指定的位置。
阅读全文