批量实现Word转PDF功能

XIAO Qinghe
XIAO Qinghe
管理员
1743
文章
0
粉丝
网络资源评论1字数 155阅读0分31秒阅读模式
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。

 
匿名

发表评论

匿名网友
确定

拖动滑块以完成验证