【MOMO_Tips】批量将word转换为PDF格式

批量将word转换为PDF格式

1.打开文件-->选项-->自定义功能区-->开发工具-->确定

2.点开开发工具,选择第一个visual basic

3.进入页面后找到插入-->模块,就可以看到这样的画面之后将下列vba代码复制粘贴到模块中

python 复制代码
Sub ConvertWordsToPdfs()
'Updated by Extendoffice 20181123
    Dim xIndex As String
    Dim xDlg As FileDialog
    Dim xFolder As Variant
    Dim xNewName As String
    Dim xFileName As String
    Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
    If xDlg.Show <> -1 Then Exit Sub
    xFolder = xDlg.SelectedItems(1) + "\"
    xFileName = Dir(xFolder & "*.*", vbNormal)
    While xFileName <> ""
        If ((Right(xFileName, 4)) <> ".doc" Or Right(xFileName, 4) <> ".docx") Then
            xIndex = InStr(xFileName, ".") + 1
            xNewName = Replace(xFileName, Mid(xFileName, xIndex), "pdf")
            Documents.Open FileName:=xFolder & xFileName, _
                ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
                PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
                WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
                wdOpenFormatAuto, XMLTransform:=""
            ActiveDocument.ExportAsFixedFormat OutputFileName:=xFolder & xNewName, _
                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
        End If
        xFileName = Dir()
    Wend
End Sub


4.按 F5 键或点击上面的运行来运行代码,会弹出浏览对话框,请选择包含要转换为pdf文件的Word文档的文件夹,然后单击OK按钮。

相关推荐
Jeremy_1213825 分钟前
word的目录和正文之间存在一张空白纸,目录后面的分节符为什么调不上去?
word
猩猩之火7 小时前
XWPFTemplate生成word
spring boot·word·动态word
风痕~~12 小时前
java实现word末尾添加图片的两种方式
java·word
不坑老师12 小时前
MarkDown语法在Word中怎么渲染?不坑盒子2025年6月8日,支持一键渲染MarkDwon了,表格、公式、图片……都可以!
word
你挚爱的强哥13 小时前
Blob设置type为application/msword将document DOM节点转换为Word(.doc,.docx),并下载到本地
开发语言·c#·word
我本梁人16 小时前
WinForms中实现Adobe PDF Reader实现旋转PDF功能
pdf·winform
gsls20080817 小时前
使用xdocreport导出word
前端·python·word
IDRSolutions_CN1 天前
如何在网页里填写 PDF 表格?
java·经验分享·pdf·软件工程·团队开发
行者将至X2 天前
解决Zotero翻译插件Zotero PDF Translate无法正常翻译
pdf
先树立一个小目标2 天前
react-pdf(pdfjs-dist)如何兼容老浏览器(chrome 49)
chrome·react.js·pdf