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

相关推荐
热爱生活的五柒5 小时前
Word 论文里参考文献经常在修改后错乱,如何解决
word
醉酒柴柴8 小时前
word创建样式以后应用于所有新文件
开发语言·学习·c#·word
DeskUI~~13 小时前
倚天剑术32--使用PDF的内容搜索功能帮你检查报销票据
pdf
珞瑜·13 小时前
Windows版Word如何启用保存时自动删除个人信息
word
l1t14 小时前
利用omnicoder-9b模型编写把扫描版pdf转成文字版pdf的程序
人工智能·python·pdf
DS随心转插件15 小时前
ChatGPT或Gemini如何生成word文档
人工智能·ai·chatgpt·word·deepseek·ds随心转
白狐_7982 天前
【疑难杂症】Word 惊现“数字 7 消失术”:特定字体 GBK 编码下的渲染陷阱排查
word
weixin_6682 天前
Agent 应该中 PDF 工具方案分析报告 - AI分析分享
人工智能·pdf
fjhcom2 天前
PDF与图片互转WEB应用开发教程
前端·pdf·图片·web应用·streamlit
polaris06302 天前
【Spring Boot 实现 PDF 导出】
spring boot·后端·pdf