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

相关推荐
tianyatest5 小时前
给 AI Agent 写了个 Skill:扫描版电子书自动解压合并 + 加书签(附 PDG 格式逆向)
ai·pdf·电子书
开开心心就好7 小时前
一元二次方程求解工具,答案带详细步骤
java·服务器·开发语言·算法·pdf·ocr·perl
闭包不眠9 小时前
网页转PDF字体出错不报错,我先看文件大小
图像处理·人工智能·计算机视觉·pdf
weixin_416660079 小时前
AI 生成的流程图和公式,怎样一起导出到 Word?附可复用测试样例
word·流程图·markdown·豆包·deepseek
鲲穹AI种草19 小时前
PDF 编辑工具怎么选,多款工具实际使用情况整理
pdf·pdf 编辑工具
阿松爱学习20 小时前
【Unity开发】Aspose.PDF的使用
unity·pdf·c#
andrsted20 小时前
练题簿在线免费刷题:Word、PDF 导题与预览补全,把现成资料变成可练习题库
微信小程序·小程序·pdf·word·学习方法·刷题
AI行业应用研究21 小时前
会务信息载体的演进:纸质、PDF 与结构化数据源的分发成本与版本一致性
大数据·人工智能·安全·小程序·架构·pdf
king135987455021 小时前
EmbeddingGemma 2 270M 实测:Mac CPU、PDF/Word、256d 与 FTS5
macos·pdf·word
2501_930707781 天前
使用C#代码从 PDF 文档中提取附件
pdf