|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub BatchWORD2PDF()
- Dim SplitPos As Integer, DotPos As Integer, FullPath As String
- Dim fdPath As Variant
- Dim str As String, n As Long, fd As FileDialog, Ext As String
- Dim t
- t = Timer
- On Error GoTo err
- Set fd = Application.FileDialog(msoFileDialogFolderPicker)
- With fd
- .Title = "选择目标文件夹"
- If .Show = -1 Then fdPath = .SelectedItems(1) Else Exit Sub
- End With
- str = Dir(fdPath & "\*.doc") '获取文件名
- While Len(str) > 0
- n = n + 1
- Documents.Open filename:=fdPath & "" & str '打开文件
- Ext = CreateObject("Scripting.FileSystemObject").GetExtensionName(str) 'FSO获取扩展名
- 'DotPos = InStrRev(str, ".") 'VBA自身方法获取扩展名
- 'If DotPos = 0 Then DotPos = Len(str)
- 'Ext = Mid(str, DotPos + 1)
- ActiveDocument.ExportAsFixedFormat OutputFileName:=(fdPath & "" & Replace(str, Ext, "pdf")), _
- ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
- wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
- Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
- CreateBookmarks:=wdExportCreateHeadingBookmarks, DocStructureTags:=True, _
- BitmapMissingFonts:=True
- ActiveDocument.Close False
- str = Dir()
- Wend
- Set fd = Nothing
- err:
- End Sub
复制代码 还未添加子目录递归。高手添加吧。 |
|