如何将多个word文档批量转换为pdf (office pdf转word)

宏:Visual Basic for Applications (VBA)

代码写在最后

步骤一:启用开发工具选项卡

文件→选项→自定义功能区→勾选开发工具

excel批量将word转成pdf,wps怎么把word批量转换成pdf

单击文件选项

excel批量将word转成pdf,wps怎么把word批量转换成pdf

选择选项菜单

excel批量将word转成pdf,wps怎么把word批量转换成pdf

勾选开发工具

步骤二:添加代码

开发工具→Visual Basic→插入模块→粘贴代码→保存

excel批量将word转成pdf,wps怎么把word批量转换成pdf

开发工具打开Visual Basic编辑器

excel批量将word转成pdf,wps怎么把word批量转换成pdf

插入模块

excel批量将word转成pdf,wps怎么把word批量转换成pdf

粘贴宏代码

步骤三:修改Word文档目录并执行

excel批量将word转成pdf,wps怎么把word批量转换成pdf

文件目录

excel批量将word转成pdf,wps怎么把word批量转换成pdf

保存宏代码后运行

excel批量将word转成pdf,wps怎么把word批量转换成pdf

执行结束

excel批量将word转成pdf,wps怎么把word批量转换成pdf

转成PDF后的文件目录

Sub doc2pdf()
'
' doc2pdf 宏
'
'
Dim file As String
ChangeFileOpenDirectory "F:\Word文件\"   '文件夹位置
 
file = Dir("*.doc")
Do Until file = ""
    On Error Resume Next '忽略错误
    Documents.Open FileName:=file
    FileName = ActiveDocument.Name
    BaseName = Left(FileName, InStrRev(FileName, ".") - 1)
    ActiveDocument.ExportAsFixedFormat OutputFileName:= _
    BaseName & ".pdf", 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
    
    ActiveDocument.Close wdDoNotSaveChanges

file = Dir
Loop
MsgBox "执行完毕:" & Date & " " & Time '执行完成后提示
End Sub