|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 chenwenming 于 2017-11-1 06:24 编辑
Microsoft Scripting Runtime
Microsoft VBcript regular Express
正则和字典的已经引用,为什么还会出现错误424呢
- Sub test()
- Dim reg As New RegExp
- Dim p As Paragraph
- Dim dic As New Scripting.Dictionary
- Dim dic2, dic3 As Scripting.Dictionary
- level1 = ""
- level2 = ""
- For Each p In Paragraphs
- reg.Pattern = "^\s*[一二三四五六七八九十]+、"
- If reg.test(p.Range.Text) Then
- Set dic2 = New Scripting.Dictionary
- dic.Add p.Range.Text, dic2
- level1 = p.Range.Text
- GoTo next1
- End If
- reg.Pattern = "^\s*[0-9]+、"
- If reg.test(p.Range.Text) And level1 <> "" Then
- If Not (dic(level1).Exists(p.Range.Text)) Then
- Set dic3 = New Scripting.Dictionary
- dic(level1).Add p.Range.Text, dic3
- End If
- level2 = p.Range.Text
- GoTo next1
- End If
- reg.Pattern = "^\s*[A-Z]+、"
- If reg.test(p.Range.Text) And level2 <> "" Then
- If Not (dic(level1)(level2).Exists(p.Range.Text)) Then
- dic(level1)(level2).Add p.Range.Text, ""
- p.Range.HighlightColorIndex = wdAuto
- Else
- 'p.Range.HighlightColorIndex = wdYellow
- p.Range.Delete
- End If
- End If
- next1:
- Next
- End Sub
复制代码
|
|