使用VBA在IE中触发事件处理程序

时间:2017-02-13 17:45:06

标签: jquery vba internet-explorer

我发现了许多类似的问题,但解决方案都是针对正在使用的页面。我试图从下拉列表中选择一个值,然后触发事件处理程序以重置页面。我不是最擅长使用HTML,我无法确定在为下拉菜单分配值后如何更新页面。这就是我所拥有的:

Dim IE As Object
Dim IECollection As Object

    Set IE = CreateObject("InternetExplorer.Application")
        IE.Visible = True
        IE.navigate "https://www.theocc.com/webapps/historical-volume-query"

    Do While IE.busy
        Application.Wait DateAdd("s", 1, Now)
    Loop

    Set IECollection =IE.Document.getElementsByName("historicalVolumeSearch.reportType")
    i = 0
    While i < IECollection.Length
        If IECollection(i).Name = "historicalVolumeSearch.reportType" Then
            IECollection(i).Value = "PC"
        End If
    i = i + 1
    Wend

我无法弄清楚接下来要从页面源代码中调用什么来进行更新。

感谢。

1 个答案:

答案 0 :(得分:0)

在这里回答我自己的问题。我离开了几个星期,然后又回到了原点,答案就在我面前。我将上面的代码更改为以下内容。按照我的意愿工作,允许我存储HTML并清除我需要的数据。

Dim IE As Object
Dim IECollection As Object
Dim IECollection2 As Object
Dim IEElement As Object
Dim dt As String

Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = False
    IE.navigate "https://www.theocc.com/webapps/put-call-ratio"

Do While IE.busy Or IE.ReadyState <> 4
    Application.Wait DateAdd("s", 1, Now)
Loop

       For i = 1 To UBound(arrDates) 'an array containing a list of dates
        dt = arrDates(i, 1)
        Set IECollection = IE.Document.getElementsByName("putCallDate")
            IECollection(0).Value = dt
            IECollection(0).Select

        Set IECollection2 = IE.Document.getElementsByTagName("form")
            j = 1
            While j < IECollection2.Length
                If IECollection2.Item(j).Name = "commandForm" Then
                    Set IEElement = IECollection2.Item(j)
                    IEElement.submit
                End If
            j = j + 1
            Wend

        Do While IE.busy Or IE.ReadyState <> 4
            Application.Wait DateAdd("s", 1, Now)
        Loop
      'other code in here that stores the HTML as a string and scrapes out data
      Next i