|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
文件夹自选。- Sub ykcbf() '//2024.7.18 word转PDF文件,文件夹自选
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set fso = CreateObject("scripting.filesystemobject")
- Set wdoc = CreateObject("Word.Application")
- wdoc.Visible = False
- With Application.FileDialog(msoFileDialogFolderPicker)
- .Title = "请选择文件夹"
- .InitialFileName = ThisWorkbook.Path & ""
- If .Show = -1 Then
- p = .SelectedItems(1) & ""
- End If
- End With
- Set ff = fso.GetFolder(p)
- For Each fd In ff.SubFolders
- For Each f In fd.Files
- If LCase(f.Name) Like "*.doc*" Then
- fnx = fso.GetExtensionName(f)
- ofn = f.Path
- fn = Replace(f.Path, f.Name, Replace(f.Name, fnx, ".pdf"))
- If Not fso.FileExists(fn) Then
- Set wd = wdoc.Documents.Open(ofn)
- wd.SaveAs2 Filename:=fn, FileFormat:=17
- wd.Close
- Else
- MsgBox "PDF已经存在: " & fn
- End If
- End If
- Next f
- Next
- wdoc.Quit
- Set wd = Nothing
- Set wdoc = Nothing
- Set fso = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
2
查看全部评分
-
|