|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
将sylun的修改下可以得到选中内容:
Sub test()
'引用Microsoft VBScript Regular Expressions 5.5
Dim mytext As String, myExp As New RegExp, myMatches
Dim i As Integer, c As Integer, mystart As Long, myend As Long, myRange As Range, deltext As String
Application.ScreenUpdating = False
mytext = ActiveDocument.Content
With myExp
.Pattern = "^(\t.+\r)(.+?)(\1)" '第一个问题的搜索模式
.Global = True
.MultiLine = True
Do '处理第一个问题,以答案内容(假设均以制表符开头)重复为线索
Set myMatches = .Execute(mytext)
If myMatches.Count = 0 Then Exit Do
For i = myMatches.Count - 1 To 0 Step -1
c = c + 1
mystart = myMatches(i).FirstIndex + myMatches(i).Length - Len(myMatches(i).SubMatches(2))
myend = myMatches(i).FirstIndex + myMatches(i).Length
Set myRange = ActiveDocument.Range(mystart, myend)
myRange.MoveStart wdParagraph, -1
myRange.Select
If myRange.Editors.Count > 0 Then Exit Do
Selection.Editors.Add wdEditorEveryone
mytext = ActiveDocument.Content
Next
Loop
.Pattern = "([\r\t]+\d+\.)(.+?)(\s?[\t\r].+?)(\d+\.\s?\2)" '第二个问题的搜索模式
Do '处理第二个问题
Set myMatches = .Execute(mytext)
If myMatches.Count = 0 Then Exit Do
For i = myMatches.Count - 1 To 0 Step -1
c = c + 1
mystart = myMatches(i).FirstIndex + myMatches(i).Length - Len(myMatches(i).SubMatches(3))
myend = myMatches(i).FirstIndex + myMatches(i).Length
ActiveDocument.Range(mystart, myend).Select
If Selection.Editors.Count > 0 Then Exit Do
Selection.Editors.Add wdEditorEveryone
mytext = ActiveDocument.Content
Next
Loop
End With
ActiveDocument.SelectAllEditableRanges wdEditorEveryone
ActiveDocument.DeleteAllEditableRanges wdEditorEveryone
Application.ScreenUpdating = True
End Sub
但只能用于相似度非常高的情况,不高的话没法使用。
八楼的代码我看过了。因为使用了替换。所以变成了文本。以我的水平目前还修改不好,只能期待守柔的文本筛来解决了。。。 |
|