2017-03-01 2 views
1

"https://investing.com/indices/us-spx-500-historical-data"의 월간 데이터를 vba를 통해 Excel로 가져 오려고했습니다. 여기 웹 테이블 데이터를 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는 월간 인덱스 번호입니다. 월간 드롭 다운 메뉴를 선택할 수는 있지만 테이블 자체는 업데이트되지 않습니다. 주간에서 월간까지이 데이터를 Excel로 가져오고 싶습니다.

답변

0

Internet Explorer에 따라이 방법을 사용해보십시오. 올바르게 이벤트를 트리거에 대한 these guys

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 

공입니다.

+0

감사합니다. IE의 이전 버전에서 작동하지만 현재 IE 버전은 작동하지 않습니다. –

관련 문제