在运行到 Cells(i + 1, 1) = objMatch.subMatche2(0)这句时出错,打印到立即窗口的结果个数29是正确的。
代码如下:
Private Sub CommandButton2_Click()
Dim strText2 As String
strText2 = Me.WebBrowser1.Document.getElementById("table_weizhi1").innerHTML
Dim objRegj As Object
Set objRegj = CreateObject("VBScript.RegExp")
objRegj.Global = True
objRegj.Pattern = "yiloutr"">[\s\S]td>(\d+?)<[\s\S]+?colorred"">(\d+?)<[\s\S]+?span>(\d+?)<[\s\S]+?span>(\d+?)<[\s\S]+?span>(\d+?)<[\s\S]+?span>(\d+?)<[\s\S]+?span>(\d+?)<[\s\S]+?span>(\d+?)<[\s\S]+?span>(\d+?)<[\s\S]+?span>(\d+?)<[\s\S]+?span>(\d+?)<"
Dim objMatche2 As Object
Set objMatche2 = objRegj.Execute(strText2)
If objMatche2.Count = 0 Then
Debug.Print "没有数据"
Exit Sub
End If
'Debug.Print objMatche2.Count '打印到立即窗口
Dim objMatch As Object, i As Long
For i = 0 To objMatche2.Count - 1
Set objMatch = objMatche2(i)
Cells(i + 1, 1) = objMatch.subMatche2(0)
Cells(i + 1, 2) = objMatch.subMatche2(1)
Cells(i + 1, 3) = objMatch.subMatche2(2)
Cells(i + 1, 4) = objMatch.subMatche2(3)
Cells(i + 1, 5) = objMatch.subMatche2(4)
Cells(i + 1, 6) = objMatch.subMatche2(5)
Cells(i + 1, 7) = objMatch.subMatche2(6)
Cells(i + 1, 8) = objMatch.subMatche2(7)
Cells(i + 1, 9) = objMatch.subMatche2(8)
Cells(i + 1, 10) = objMatch.subMatche2(9)
Cells(i + 1, 11) = objMatch.subMatche2(10)
Next
End Sub