批量word转pdf——VBS脚本,在office宏中运行即可

这个VBS脚本可以在Office宏中运行,实现批量将Word文档转换为PDF格式。通过设置Application.DisplayAlerts和ScreenUpdating为False来提高效率,并使用FileDialog选择Word文件,然后使用Word应用程序的SaveAs方法保存为PDF格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

批量word转pdf——VBS脚本,在office宏中运行即可 

Sub 批量word转pdf()

  Application.DisplayAlerts = False
  Application.ScreenUpdating = False
Dim fDialog As FileDialog
  Set fDialog = Application.FileDialog(msoFileDialogFilePicker) '返回一个 FileDialog 对象,该对象代表文件对话框的单个实例。
Dim vrtSelectedItem As Variant
Dim wdDoc As Document
Dim showFolder As Boolean
  showFolder = False
  With fDialog
    .Filters.Add "Word文件", "*.doc;*.docx;*.docm", 1
    If .Show = -1 Then
      For Each vrtSelectedItem In .SelectedItems
        '如果选择了本文档则跳过
        If InStrRev(vrtSelectedItem, ThisDocument.Name) = 0 Then
          On Error Resume Next
          Set wdDoc = Application.Documents.Open(vrtSelectedItem, ReadOnly:=True)
          wdDoc.SaveAs Left(vrtSelectedItem, Len(vrtSelectedItem) - 5), wdFormatPDF
          wdDoc.Close False
        End If
      Next vrtSelectedItem
      If showFolder Then Call Shell("explorer.exe " & Left(fDialog.SelectedItems(1), _
         InStrRev(fDialog.SelectedItems(1), "")), vbMaximizedFocus)
    End If
  End With
  Set fDialog = Nothing
  Application.ScreenUpdating = True

  Application.DisplayAlerts = True

End Sub
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

智慧安全方案

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值