梦霖 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 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题
  • ¥15 腾讯IOA系统怎么在文件夹里修改办公网络的连接