|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub shishi()
- Dim mt, mh, mk, oRng As Range, rg As Range, n&, m&, str$, d, rng As Range
- Set d = CreateObject("Scripting.Dictionary")
- y = 4
- With CreateObject("vbscript.regexp")
- .Global = True: .IgnoreCase = False: .MultiLine = True
- .Pattern = "^\d+.[^\r]+\(([A-E])\)\r(?:(?!^\d+.[^\r]+\((?:[A-E])\)\r).)+"
- For Each mt In .Execute(ActiveDocument.Content)
- y = y + 1
- m = mt.FirstIndex: n = mt.Length
- Set oRng = ActiveDocument.Range(m, m + n)
- str = mt.submatches(0)
- .Pattern = "([A-E].)((?:(?![A-E].).)+)"
- For Each mh In .Execute(oRng.Text)
- m = mh.FirstIndex: n = mh.Length
- Set rg = ActiveDocument.Range(oRng.Start + m, oRng.Start + m + n)
- Set d(Left(rg.Text, 1)) = rg
- Next
- t = d.items
- Select Case y Mod 5
- Case 0
- If str <> "A" Then
- .Pattern = "\(\s*[A-E]\s*\)"
- For Each mk In .Execute(oRng.Text)
- m = mk.FirstIndex: n = mk.Length
- Set rng = ActiveDocument.Range(oRng.Start + m, oRng.Start + m + n)
- With rng
- .MoveStart 1, 1: .MoveEnd 1, -1: .Text = "A"
- End With
- Next
- With d(str)
- .MoveStart 1, 2: .MoveEnd 1, -1: s1 = .Text
- End With
- With t(0)
- .MoveStart 1, 2: .MoveEnd 1, -1: s2 = .Text
- .Text = s1
- End With
- d(str).Text = s2
- End If
- Case 1
- If str <> "B" Then
- .Pattern = "\(\s*[A-E]\s*\)"
- For Each mk In .Execute(oRng.Text)
- m = mk.FirstIndex: n = mk.Length
- Set rng = ActiveDocument.Range(oRng.Start + m, oRng.Start + m + n)
- With rng
- .MoveStart 1, 1: .MoveEnd 1, -1: .Text = "B"
- End With
- Next
- With d(str)
- .MoveStart 1, 2: .MoveEnd 1, -1: s1 = .Text
- End With
- With t(1)
- .MoveStart 1, 2: .MoveEnd 1, -1: s2 = .Text
- .Text = s1
- End With
- d(str).Text = s2
- End If
- Case 2
- If str <> "C" Then
- .Pattern = "\(\s*[A-E]\s*\)"
- For Each mk In .Execute(oRng.Text)
- m = mk.FirstIndex: n = mk.Length
- Set rng = ActiveDocument.Range(oRng.Start + m, oRng.Start + m + n)
- With rng
- .MoveStart 1, 1: .MoveEnd 1, -1: .Text = "C"
- End With
- Next
- With d(str)
- .MoveStart 1, 2: .MoveEnd 1, -1: s1 = .Text
- End With
- With t(2)
- .MoveStart 1, 2: .MoveEnd 1, -1: s2 = .Text
- .Text = s1
- End With
- d(str).Text = s2
- End If
- Case 3
- If str <> "D" Then
- .Pattern = "\(\s*[A-E]\s*\)"
- For Each mk In .Execute(oRng.Text)
- m = mk.FirstIndex: n = mk.Length
- Set rng = ActiveDocument.Range(oRng.Start + m, oRng.Start + m + n)
- With rng
- .MoveStart 1, 1: .MoveEnd 1, -1: .Text = "D"
- End With
- Next
- With d(str)
- .MoveStart 1, 2: .MoveEnd 1, -1: s1 = .Text
- End With
- With t(3)
- .MoveStart 1, 2: .MoveEnd 1, -1: s2 = .Text
- .Text = s1
- End With
- d(str).Text = s2
- End If
- Case 4
- If str <> "E" Then
- .Pattern = "\(\s*[A-E]\s*\)"
- For Each mk In .Execute(oRng.Text)
- m = mk.FirstIndex: n = mk.Length
- Set rng = ActiveDocument.Range(oRng.Start + m, oRng.Start + m + n)
- With rng
- .MoveStart 1, 1: .MoveEnd 1, -1: .Text = "E"
- End With
- Next
- With d(str)
- .MoveStart 1, 2: .MoveEnd 1, -1: s1 = .Text
- End With
- With t(4)
- .MoveStart 1, 2: .MoveEnd 1, -1: s2 = .Text
- .Text = s1
- End With
- d(str).Text = s2
- End If
- End Select
- d.RemoveAll
- Next
- End With
- End Sub
复制代码 |
评分
-
3
查看全部评分
-
|