【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按钮。

相关推荐
2301_816997884 小时前
Word版本介绍与选择
c#·word·xhtml
2301_816997886 小时前
Word界面完全解析
word·xhtml
汤姆百宝箱9 小时前
2026新版教材电子课本1-9年级新教材PDF(完整电子版下载)
pdf·小学课本·初中课本·电子教材·电子课本·2026新教材·2026新课本
开开心心就好9 小时前
内存清理软件灵活设置,自动阈值快捷键清
运维·服务器·windows·pdf·harmonyos·risc-v·1024程序员节
海兰9 小时前
【接上篇】多格式文档支持扩展方案(PDF_Word_Excel)
pdf·word·excel
松叶似针9 小时前
Flutter三方库适配OpenHarmony【doc_text】— Word 文档解析插件功能全景与适配价值
flutter·word·harmonyos
reasonsummer9 小时前
【办公类-109-10】20260228圆牌被子牌(接送卡&被子卡&床卡&入园卡_word编辑单面_添加有效期)
python·word
道纪书生10 小时前
解决报错:很抱歉,powerpoint/word/excel遇到错误,使其无法正常工作......
word·powerpoint·excel
南部余额10 小时前
Apache POI 从入门到实战:Excel 与 Word操作攻略
java·word·excel·poi
鸿乃江边鸟10 小时前
用 oh-my-opencode 写一个word转pdf skill
pdf·大模型·opencode