2016-09-20 189 views
0

我們如何選擇使用VBA下拉選項?使用Excel VBA通​​過懸停下拉菜單點擊

例如,我的HTML源代碼看起來像下面,我儘量選擇第二個,「코스피200선물」。

<select name="isu_cd" id="isu_cdc74d97b01eae257e44aa9d5bade97baf"> 
    <option value="ALL">전체</option> 
    <option value="KRDRVFUK2I">코스피200 선물</option> 
    .... 
</select> 

因此,我嘗試在選擇具有name =「isu_cd」後使用「For Each」進行迭代。

但測試「MSGBOX(botton.innnerHTML)」中的「爲每個」給了我充分的HTML代碼中包含所有其他選項意外。

Unexpected Results

難道我們遍歷這個跟我的做法?

Sub test_javascript() 

    url = "http://marketdata.krx.co.kr/mdi#document=060101" 

    Set ie = CreateObject("InternetExplorer.Application") 
     ie.Visible = True 
     ie.navigate url 

    Do Until (ie.readyState = 4 And Not ie.Busy) 
     DoEvents 
    Loop 

    Application.Wait (Now + TimeValue("00:00:10")) 

    Set Buttons = ie.document.getElementsByName("isu_cd") 

    For Each botton In Buttons 

     MsgBox (botton.innerHTML) 'it gives all of HTML code unexpectedly 

     If botton.innerHTML = "코스피200 선물" Then 'Nothing comes to here 
      MsgBox (botton.innerHTML) 
      botton.FireEvent ("onchange") 
      Exit For 
     End If 
    Next 

End Sub 
+0

爲什麼VBA?使用jQuery使得它更容易實現。 '選擇不具備的值「點擊」事件「=>您可以使用'