|
试了下效果,效率太低:- Sub kk遍历指定目录及其子目录所有文档()
- Dim wDia As FileDialog
- Dim n As Long
- Dim wDoc As Document
- Dim wRng As Range
- Dim wPath As String, wStr As String
- Set wDia = Application.FileDialog(msoFileDialogFolderPicker)
- With wDia
- If .Show = 0 Then Exit Sub
- wPath = .SelectedItems(1)
- End With
- Application.ScreenUpdating = False
- With Application.FileSearch
- .NewSearch
- .LookIn = wPath
- .SearchSubFolders = True
- .FileName = "*.docx"
- '.FileType = msoFileTypeWordDocuments
- If .Execute() = 0 Then Exit Sub
- For n = 1 To .FoundFiles.Count
- Set wDoc = Documents.Open(FileName:=.FoundFiles(n), Visible:=False)
- Set wRng = wDoc.Range(wDoc.Paragraphs(1).Range.Start, wDoc.Paragraphs(1).Range.End - 1)
- wStr = Replace(Replace(wRng, "14", "15"), "13", "14")
- wRng.Delete
- wRng.InsertAfter wStr
- wDoc.Close True
- Next n
- End With
- Application.ScreenUpdating = True
- MsgBox "共修改了 " & n - 1 & " 个文档!", vbExclamation
- End Sub
复制代码 |
|