Sub BatchConvertWordToPDF()
Dim folderPath As String
Dim wordFile As String
Dim doc As Document
folderPath = InputBox("请输入包含 Word 文件的文件夹路径", "选择文件夹")
If folderPath = "" Then Exit Sub
wordFile = Dir(folderPath & "\*.docx")
Do While wordFile <> ""
Set doc = Documents.Open(folderPath & "\" & wordFile)
doc.ExportAsFixedFormat OutputFileName:=folderPath & "\" & Replace(wordFile, ".docx", ".pdf"), _
ExportFormat:=wdExportFormatPDF
doc.Close False
wordFile = Dir()
Loop
MsgBox "批量转换完成!"
End Sub(1)打开任意 Word 文档,按下 Alt + F11 打开 VBA 编辑器(点击“开发工具”,点击“visual Basic”)
(2)在Project(文档)右键鼠标,点击“插入”,选择“模块”,复制以上代码。
(3)运行脚本,即可将指定文件夹内所有 .docx 批量转为 PDF。







