|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 kqbt 于 2015-11-13 08:45 编辑
2003版本下试一下吧,做好备份,我自己未进行测试:
- Sub 标注不成对标点符号()
- Dim iPath As String, j As Long
- With Application.FileDialog(msoFileDialogFolderPicker)
- If .Show Then
- iPath = .SelectedItems(1)
- End If
- End With
- If iPath = "False" Then Exit Sub
- With Application.FileSearch
- .NewSearch
- .LookIn = iPath
- .SearchSubFolders = False
- .FileName = "*.doc"
- If .Execute() > 0 Then
- For j = 1 To .FoundFiles.Count
- iPath = .FoundFiles(j)
- ERR_BD (iPath)
- Next
- End If
- End With
- MsgBox "标注完成!"
- End Sub
- '======注意======3版
- '1 跨段落匹配不视为成对
- '2 同标点多层嵌套匹配不视为成对
- '3 未测试表格中的标点
- '================
- Function ERR_BD(iPath As String)
- Dim Arr(), i As Integer, m As Integer, n As Integer, o As Integer, t As Long
- Dim wDoc As Document, wRng As Range, rRng As Range, sRng As Range, tRng As Range
- 'ActiveDocument.Content.HighlightColorIndex = wdAuto
- 'ActiveDocument.Content.Font.Color = wdColorRed</p><p> Application.ScreenUpdating = False
- Arr = Array(-24146, -24145, -24144, -24143, -24142, -24141, -24140, -24139, -24138, _
- -24137, -24136, -24135, -24134, -24133, -24132, -24131, -24130, -24129, _
- -23640, -23639, -23620, -23618, -23589, -23587, -23557, -23555, _
- 40, 41, 60, 62, 91, 93, 123, 125)
- t = 0
- Set wDoc = Documents.Open(iPath)
- wDoc.Activate
- For i = 0 To UBound(Arr)
- Selection.HomeKey wdStory
- Set wRng = Selection.Range
- m = 1: n = 0: o = i Mod 2
- If o = 0 Then
- line1:
- wRng.MoveUntil Chr(Arr(i))
- Set rRng = ActiveDocument.Range(wRng.End, wRng.End + 1).Duplicate
- If rRng = Chr(Arr(i)) Then
- wRng.MoveUntil Chr(Arr(i + m))
- Set sRng = ActiveDocument.Range(wRng.End, wRng.End + 1).Duplicate
- If sRng = Chr(Arr(i + m)) Then
- Set tRng = ActiveDocument.Range(rRng.End, sRng.End)
- If InStr(tRng, Chr(Arr(i + n))) Or tRng.Paragraphs.Count > 1 Then
- 'rRng.HighlightColorIndex = wdBrightGreen
- rRng.Font.Color = wdColorRed
- wRng.SetRange rRng.Start, rRng.End
- t = t + 1
- End If
- GoTo line1
- Else
- 'rRng.HighlightColorIndex = wdBrightGreen
- rRng.Font.Color = wdColorRed
- wRng.SetRange rRng.Start, rRng.End
- t = t + 1
- GoTo line1
- End If
- End If
- Else
- m = m - 1: n = n - 1
- Set rRng = wRng.Duplicate
- line2:
- wRng.MoveUntil Chr(Arr(i + m))
- Set sRng = ActiveDocument.Range(wRng.End, wRng.End + 1).Duplicate
- If sRng = Chr(Arr(i + m)) Then
- Set tRng = ActiveDocument.Range(rRng.End, sRng.End)
- If tRng.Paragraphs.Count > 1 Then
- tRng.SetRange wRng.Paragraphs(1).Range.Start, tRng.End
- End If
- If InStr(tRng, Chr(Arr(i + n))) = 0 Or InStr(tRng, Chr(13)) Then
- 'sRng.HighlightColorIndex = wdBrightGreen
- sRng.Font.Color = wdColorRed
- t = t + 1
- End If
- wRng.SetRange sRng.Start, sRng.End
- Set rRng = wRng.Duplicate
- GoTo line2
- End If
- End If
- Next
- Set wRng = ActiveDocument.Content
- With wRng.Find
- .ClearFormatting
- .Replacement.ClearFormatting
- Do While .Execute("^13[0-9一二三四五六七八九十百]@[/))]", , , True, , , True)
- 'wRng.HighlightColorIndex = wdAuto
- wRng.Font.Color = wdColorAutomatic
- wRng.SetRange wRng.End, ActiveDocument.Content.End
- t = t - 1
- Loop
- End With
- wDoc.Close True
- Application.ScreenUpdating = True
- 'MsgBox "共标注了 " & t + 1 & " 个不成对标点!"
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|