我們如何選擇使用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代碼中包含所有其他選項意外。
難道我們遍歷這個跟我的做法?
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
爲什麼VBA?使用jQuery使得它更容易實現。 '選擇不具備的值「點擊」事件「=>您可以使用'
謝謝。我想在你的路上這樣做。但我目前正在使用Excel VBA來滿足公司 – JonghoKim
的具體需求哦,我明白了。您將網頁嵌入到您的VBA表單中。你的VBA表格想要檢測網頁中選擇的值。所以你可以用它來達到另一個目的。 –