|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
* 139:过奖了!——建议批量处理不要太多,以免不响应。----下面是两个宏,看清宏名执行之,一般可以按 Alt+F8 找到所需宏双击或点击“运行”按钮,常用的也可以拖到工具栏上成为按钮,或设宏为热键F3/F4。
- Sub 循环遍历文件夹_查找重复标点符号()
- On Error Resume Next
- Dim fd As FileDialog, i As Long, doc As Document, p As String, t As Long, s As Long, j As Paragraph
- 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.Find.Execute findtext:="(", ReplaceWith:="(", Replace:=wdReplaceAll
- doc.Content.Find.Execute findtext:=")", ReplaceWith:=")", Replace:=wdReplaceAll
- '查找重复标点符号
- For Each j In doc.Paragraphs
- j.Range.Select
- If Len(j.Range) = 1 Then GoTo SkipEmpty
- Selection.HomeKey Unit:=wdLine
- Do
- Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
- If Selection.Characters.Last Like vbCr Then GoTo SkipEmpty
- If Selection.Characters.Last Like "[。;:,、!?;:,.?!…—]" Then
- Do
- Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
- Loop Until Selection.Characters.Last Like "[!。;:,、!?;:,.?!…—]"
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- If Len(Selection) > 1 And Not (Selection Like "……") And Not (Selection Like "——") Then
- Selection.Font.Color = wdColorBlue '蓝色
- ' Selection.Range.HighlightColorIndex = wdBrightGreen '突出显示(鲜绿)
- End If
- End If
- Selection.MoveRight Unit:=wdCharacter, Count:=1
- Loop
- SkipEmpty:
- Next
- doc.Close savechanges:=wdSaveChanges
- Next i
- MsgBox "处理完毕!共处理 " & .FoundFiles.Count & " 个文件!", vbOKOnly + vbExclamation, "循环遍历文件夹_查找重复标点符号"
- Else
- MsgBox "未发现文件!", vbOKOnly + vbCritical, "循环遍历文件夹_查找重复标点符号"
- End If
- End With
- End Sub
- Sub 循环遍历文件夹_替换英文括号为中文()
- On Error Resume Next
- Dim fd As FileDialog, i As Long, doc As Document, p As String, t As Long, s As Long, j As Paragraph
- 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.Find.Execute findtext:="(", ReplaceWith:="(", Replace:=wdReplaceAll
- doc.Content.Find.Execute findtext:=")", ReplaceWith:=")", Replace:=wdReplaceAll
- doc.Close savechanges:=wdSaveChanges
- Next i
- MsgBox "处理完毕!共处理 " & .FoundFiles.Count & " 个文件!", vbOKOnly + vbExclamation, "循环遍历文件夹_查找重复标点符号"
- Else
- MsgBox "未发现文件!", vbOKOnly + vbCritical, "循环遍历文件夹_查找重复标点符号"
- End If
- End With
- End Sub
复制代码 |
|