2017-02-13 69 views
0

我發現了許多類似的問題,但解決方案都是特定於正在處理的頁面。我試圖從下拉列表中選擇一個值,然後觸發事件處理程序來重置頁面。我不是最擅長使用HTML,我無法確定如何在爲下拉菜單指定值後獲取頁面更新。這是我有:使用VBA在IE中觸發事件處理程序

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

會更容易使用網頁中列出的選項:https://www.theocc.com/market-data/batch-processing.jsp –

+0

@TimWilliams不幸的是我需要的數據是不容易提取從批處理報告。還有其他建議嗎? – amdopt

回答

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 
相關問題