想搜索一篇word文档的序号所在行,并把行数记录在数组中。基本思路是:循环每一个段落,然后在每个段落的range中find序号。然而在执行过程中出现混乱,找了找了好几天,不知问题出哪里了,急急!
这是代码
For i = 1 To 10000 'ActiveDocument.Paragraphs.Count
If i = daan_d Then
MsgBox "发现最大题号为:" & UBound(r)
Call jc_sz
Exit For
End If
Set a = ActiveDocument.Paragraphs(i).Range
If Not a.Information(12) Then
a.SetRange a.Start, a.Start + 3
a.Select
With Selection.Find
.ClearFormatting
.MatchByte = False
.Forward = False
.Wrap = wdFindStop
'.Text = xuhao & "."
.Text = "[0-9]{1,2}[..。。]"
.MatchWildcards = True
.Execute
If .Found = True Then
Set a = Selection.Range
a.Select
a.Font.Fill.ForeColor = vbRed
Call shuzu(Left$(a.Text, Len(a.Text) - 1), i)
End If
End With
End If
Next
前面序号可以很好的find到,到第10题出错了,我设定只find每行的前4个字符,但是第10题的D选项的第15个字符被find到了,很奇怪,就是这个bug,迷茫了