Word VBA另存为PDF,可选储存位置,另存时可改名
时间: 2023-11-26 18:05:09 浏览: 102
可以使用下面的代码来实现Word VBA另存为PDF,并且可以选择储存位置和更改文件名:
```vb
Sub SaveAsPDF()
Dim filePath As String
Dim fileName As String
'获取要保存的文件名和路径
filePath = Application.GetSaveAsFilename(fileFilter:="PDF Files (*.pdf), *.pdf")
If filePath = "False" Then Exit Sub
fileName = Mid(filePath, InStrRev(filePath, "\") + 1)
'另存为PDF文件
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
filePath, 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
'更改文件名
If fileName <> "" And fileName <> ActiveDocument.Name Then
Name filePath As Left(filePath, InStrRev(filePath, "\") - 1) & "\" & fileName
End If
End Sub
```
这段代码会弹出一个对话框,让你选择要保存的位置和文件名。如果你不想更改文件名,直接点击保存即可。如果你想更改文件名,输入新的文件名,然后点击保存即可。
阅读全文
相关推荐

















