梦霖 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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助