2016-09-20 190 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使得它更容易实现。 '选择不具备的值“点击”事件“=>您可以使用'