word批量转pdf

方法:使用Microsoft Word批处理宏

批量实现Word转PDF功能,适合办公人员。无需安装额外软件,操作简单,原生支持。

(1)打开任意 Word 文档,按下 Alt + F11 打开 VBA 编辑器(点击“开发工具”,点击“visual Basic”)

 

image

(2)在Project(文档)右键鼠标,点击“插入”,选择“模块”,复制以下代码:

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

(3)运行脚本,即可将指定文件夹内所有 .docx 批量转为 PDF。

image

 

posted @ 2025-10-24 17:12  帅帅的飞猪  阅读(10)  评论(0)    收藏  举报