2017-03-01 10 views
1

月間データを "https://investing.com/indices/us-spx-500-historical-data"からvbaに変換したいと思っていました。ここでWebテーブルのデータをExcelに取得

は、時間枠]ドロップダウンメニューのソースコードである: - ここに

<select id="data_interval" class="newInput selectBox float_lang_base_1"> 
     <option value="Daily" selected="">Daily</option> 
     <option value="Weekly">Weekly</option> 
     <option value="Monthly">Monthly</option> 
    </select>enter code here 

は、表のソースコードである:ここで

<table class="genTbl closedTbl historicalTbl" id="curr_table" tablesorter="">enter code here 

は、私が使用していますVBAコードで、

Sub GetData() 
Dim IE As Object 
Dim Links 
Set IE = CreateObject("InternetExplorer.Application") 
IE.navigate ("https://uk.investing.com/indices/us-spx-500-historical-data") 
IE.Visible = True 
Do 
    DoEvents 
Loop Until IE.readyState = 4 
Set Links = IE.document.getElementById("data_interval") 
Links.selectedIndex = 2 
End Sub 

2は月間インデックス番号です。Monthly fromドロップダウンメニューを選択できますが、テーブル自体は更新されません毎週から毎月、このデータをExcelにも取得したいと考えています。

答えて

0

このようにすると、Internet Explorerによってはうまくいくかもしれません。

Option Explicit 

Sub GetData() 

    Dim IE  As Object 
    Dim Links As Object 
    Dim evt  As Object 

    Set IE = CreateObject("InternetExplorer.Application") 
    IE.navigate ("https://uk.investing.com/indices/us-spx-500-historical-data") 
    IE.Visible = True 
    Do 
     DoEvents   
    Loop Until IE.readyState = 4 

    Set Links = IE.document.GetElementById("data_interval") 
    Set evt = IE.document.createevent("htmlevents") 
    evt.initevent "change", True, False 

    Links.Focus 
    Links.SelectedIndex = 2 
    Links.FireEvent ("onChange") 

    Links.dispatchevent evt 

End Sub 

トリビュートにthese guysイベントを正しく実行するためです。

+0

ありがとうございました。以前のバージョンのIEでは動作しましたが、現在のIEバージョンでは動作しませんでした。 –

関連する問題