使用VBA批量将Word转成PDF

Sub ConvertWordToPDF()
Dim folderPath As String
Dim wordFile As String
Dim pdfFile As String
Dim wordApp As Object

'设置要转换的文件夹路径
folderPath = "C:\Users\JIAHE\Desktop\Output\"

'创建Word应用程序对象
Set wordApp = CreateObject("Word.Application")

'关闭屏幕更新,加快转换速度
wordApp.ScreenUpdating = False

'循环遍历目录下的所有Word文件
wordFile = Dir(folderPath & "*.doc*")
Do While wordFile <> ""
'构造PDF文件名
pdfFile = Left(wordFile, Len(wordFile) - 4) & ".pdf"

'打开Word文件
wordApp.Documents.Open folderPath & wordFile

'将Word文件保存为PDF文件
wordApp.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
folderPath & pdfFile, ExportFormat:=17, OpenAfterExport:=False

'关闭Word文档
wordApp.ActiveDocument.Close

'获取下一个Word文件名
wordFile = Dir()
Loop

'关闭Word应用程序
wordApp.Quit

'恢复屏幕更新
Application.ScreenUpdating = True

End Sub