【Word】批量将word转换为PDF

仅需Word软件

STPE 1: 新建空白文档,无需保存;

STPE 2: 文件 -> 选项 -> 自定义功能区 -> 勾选开发工具;

在这里插入图片描述

STPE 3: 在word界面选择 “开发工具” ,插入 -> 模块,复制粘贴代码;

在这里插入图片描述

STPE 4: 运行代码,选择包含所需转换的Word文档的文件夹。

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
  End If
  
  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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值