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

相关推荐
tedcloud1235 小时前
DeepSeek-TUI部署教程:打造CLI AI助手环境
服务器·人工智能·word·excel·dreamweaver
asdzx675 小时前
使用 Python 快速提取 PDF 中的表格
python·pdf
南风微微吹8 小时前
2026英语六级作文模版万能句子PDF电子版
pdf·英语六级
又是被bug折磨的一天9 小时前
对多个pdf合同文件批量命名
pdf
南风微微吹11 小时前
2026年英语四级作文模版万能句子PDF电子版
pdf·英语四级
aihuangwu12 小时前
AI导出鸭|ChatGPT与Gemini生成Word文档技术实操
人工智能·ai·chatgpt·word·deepseek·ai导出鸭
这是个假程序员13 小时前
PDF分色、智能PDF黑彩识别工具
pdf
夜勤月13 小时前
HarmonyOS 6.0 ArkWeb实战:PDF背景色自定义功能全解析(附完整代码+避坑指南)
华为·pdf·harmonyos
relis14 小时前
AI使用小技巧: 用zed和MinerU本地版,同时学习PDF文档的文字和图片
ai·pdf·大模型·agent
海盗123414 小时前
C#中PDF操作-QuestPDF页面设置与布局
java·pdf·c#