|
多文档代码(未做测试,每篇文档为红色不好吧?)
- Sub 循环遍历文件夹_查找数字之间中文冒号_Part1()
- 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.Content.Font.Color = wdColorRed '处理单个文档(通用)
- 'Sub 查找数字之间的中文冒号()
- Selection.HomeKey Unit:=wdStory
- Selection.Find.ClearFormatting
- Do While Selection.Find.Execute(FindText:=":", Forward:=True)
- Selection.MoveStart Unit:=wdCharacter, Count:=-1
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Selection Like "[0-9]?[0-9]" Then
- Selection.MoveStart Unit:=wdCharacter, Count:=1
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- Selection.Font.Color = wdColorRed '红色
- End If
- Selection.MoveRight Unit:=wdCharacter, Count:=1
- Loop
- '''
- doc.Close savechanges:=wdSaveChanges
- Next i
- MsgBox "处理完毕!共处理 " & .FoundFiles.Count & " 个文件!", vbOKOnly + vbExclamation, "循环遍历文件夹_通用"
- Else
- MsgBox "未发现文件!", vbOKOnly + vbCritical, "循环遍历文件夹_通用"
- End If
- End With
- End Sub
- Sub 循环遍历文件夹_数字之间红色中文冒号转英文_Part2()
- 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.Content.Font.Color = wdColorRed '处理单个文档(通用)
- 'Sub 查找数字之间的红色中文冒号()
- Selection.HomeKey Unit:=wdStory
- Selection.Find.ClearFormatting
- Do While Selection.Find.Execute(FindText:=":", Forward:=True)
- Selection.MoveStart Unit:=wdCharacter, Count:=-1
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Selection Like "[0-9]?[0-9]" Then
- Selection.MoveStart Unit:=wdCharacter, Count:=1
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- If Selection.Font.Color = wdColorRed Then Selection.Text = ":"
- End If
- Selection.MoveRight Unit:=wdCharacter, Count:=1
- Loop
- '''
- doc.Close savechanges:=wdSaveChanges
- Next i
- MsgBox "处理完毕!共处理 " & .FoundFiles.Count & " 个文件!", vbOKOnly + vbExclamation, "循环遍历文件夹_通用"
- Else
- MsgBox "未发现文件!", vbOKOnly + vbCritical, "循环遍历文件夹_通用"
- End If
- End With
- End Sub
复制代码 |
|