|
楼主 |
发表于 2024-8-25 13:45
|
显示全部楼层
过程不能正常运行,改了一下,添加了红色字符。
Sub 要求匹配解析捕获四个2()
Dim mt, mk, oRng As Range, n&, m&
Dim str$, tt$, arr() As Range, x%
Dim rg As Range, dic As Object, k&, ph As Paragraph
Set Ydoc = ThisDocument
Set dic = CreateObject("Scripting.Dictionary")
osr = Ydoc.Content
Set wdoc = ActiveDocument
'************************
Set ph = wdoc.Paragraphs(1)
Set wt = ph.Range.Words(ph.Range.Words.Count - 1)
r = wt.End - wt.Start
s = 3 '控件终止符1+回车符2
'*************************
str = Replace(Replace(osr, Chr(7), ""), Chr(1), 0)
With CreateObject("vbscript.regexp")
.Global = True
.Ignorecase = False
.MultiLine = True
.Pattern = "(^解析\s*)([A-D].*?){3}$"
For Each mt In .Execute(str)
'文档有控件时使用
'm = mt.FirstIndex + r + s: n = mt.Length - s
m = mt.FirstIndex: n = mt.Length
Set oRng = Ydoc.Range(m, m + n)
MsgBox oRng
Next
End With
End Sub
不能达到预期效果。请测试附件 |
|