|
本帖最后由 413191246se 于 2019-8-31 10:40 编辑
楼主,请备份后试用:- Sub tet循环遍历文件夹_替换指定位置字符()
- On Error Resume Next
- Dim fd As FileDialog, i As Long, doc As Document, p As String
- Set fd = Application.FileDialog(msoFileDialogFolderPicker)
- If fd.Show = -1 Then p = fd.SelectedItems(1) Else Exit Sub
- Set fd = Nothing
- If MsgBox("是否处理文件夹 " & p & " ?", vbYesNo + vbExclamation, "循环遍历文件夹_通用") = vbNo Then Exit Sub
- With Application.FileSearch
- .NewSearch
- .LookIn = p
- .SearchSubFolders = True
- .FileName = "*.doc"
- If .Execute > 0 Then
- For i = 1 To .FoundFiles.Count
- Set doc = Documents.Open(FileName:=.FoundFiles(i))
- doc.Range(Start:=doc.Tables(2).Range.Cells(16).Range.Start, End:=doc.Tables(2).Range.Cells(41).Range.End).Select
- Selection.Find.Execute " ", , , 0, , , , , , "", 2
- doc.Range(Start:=doc.Tables(2).Range.Cells(17).Range.Start, End:=doc.Tables(2).Range.Cells(42).Range.End).Select
- Selection.Find.Execute ";", , , 0, , , , , , ",", 2
- doc.Close savechanges:=wdSaveChanges
- Next i
- MsgBox "处理完毕!共处理 " & .FoundFiles.Count & " 个文件!", vbOKOnly + vbExclamation, "循环遍历文件夹_通用"
- Else
- MsgBox "未发现文件!", vbOKOnly + vbCritical, "循环遍历文件夹_通用"
- End If
- End With
- End Sub
复制代码
|
|