梦霖 2021-11-20 13:13 采纳率: 100%
浏览 30
已结题

VBA中Web窗本控件获取的结果如何将写入单元格?

在运行到 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

img

img

img

  • 写回答

1条回答 默认 最新

报告相同问题?

问题事件

  • 系统已结题 11月28日
  • 已采纳回答 11月20日
  • 创建了问题 11月20日

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题