|
- Dim aFolder$, aNum&, arr, i&, aDoc As Document
- With Application.FileDialog(msoFileDialogFolderPicker) '选择目录
- aFolder = .SelectedItems(1)
- If Right(aFolder, 1) <> "" Then aFolder = aFolder & ""
- End With
- aFolder = """" & aFolder & """"
- With CreateObject("WScript.Shell") '遍历结果到文件
- .Run Environ$("comspec") & " /c dir " & aFolder & " /s /a:-d /b > C:\aTemp.txt", 0, True
- aNum = FreeFile
- Open "C:\aTemp.txt" For Input As #aNum '读取文件
- arr = Split(StrConv(InputB(LOF(aNum), aNum), vbUnicode), vbCrLf)
- Close #aNum
- .Run Environ$("comspec") & " /c delele /f /q C:\aTemp.txt", 0, True '删除临时文件
- End With
- For i = 1 To UBound(arr) - 1 '循环处理文件
- Set aDoc = Documents.Open(arr(i))
- With aDoc.Content.Find
- .ClearFormatting
- .Replacement.ClearFormatting
- .Replacement.Font.ColorIndex = wdBlue
- .Text = "[,。!?:;、.]{2,}"
- .Forward = True
- .Wrap = wdFindStop
- .Format = True
- .MatchWildcards = True
- .Execute Replace:=wdReplaceAll
- End With
- Next
- Application.ScreenUpdating = True
复制代码 |
|