|
本帖最后由 loquat 于 2014-12-21 14:32 编辑
请测试- Sub 查找替换_loquat()
- Application.ScreendUpdating = False
- Dim arr, folder$
- Dim aDoc As Document, aRange As Range
- folder = """" & "C:\Program Files" & """" '设置文件路径
- With CreateObject("WScript.Shell")
- .Run Environ$("comspec") & " /c dir " & folder & "*.doc /s /a:-d /b > C:\temp.txt", 0, True
- End With
- aNum = FreeFile
- Open "C:\temp.txt" For Input As #aNum
- arr = Split(StrConv(InputB(LOF(aNum), aNum), vbUnicode), vbCrLf)
- Close #aNum
- For i = 0 To UBound(arr)
- Set aDoc = Documents.Open(arr(i))
- Set aRange = aDoc.Content
- With aRange.Find
- .ClearFormatting
- .Replacement.ClearFormatting
- .Text = "建设一班"
- .Replacement.Text = "建设二班"
- .Forward = True
- .Wrap = wdFindStop
- .MatchByte = True
- .Execute Replace:=wdReplaceAll
- End With
- aDoc.Close True
- Next
- Application.ScreendUpdating = True
- End Sub
复制代码 |
|