HTML 下拉列表的选定选项的 VBA 内部文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20180437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA innertext of the selected option for HTML dropdown list
提问by TPJ87
Is there a way to select the innertext of the selected option for a webpages dropdown list? I was trying this way but kept getting an error Object Required:
有没有办法为网页下拉列表选择所选选项的内部文本?我正在尝试这种方式,但一直收到错误 Object Required:
Dim drp As Object
Set drp = IE.Document.getElementById("ctl05_Dropdownlist1").selectedindex
Range("J" & (ActiveCell.Row)) = drp.innertext
Im trying to pull the selected options innertext from the following part of HTML sourcecode:
我试图从 HTML 源代码的以下部分中提取选定的选项内文:
<select name="ctl05$Dropdownlist1" id="ctl05_Dropdownlist1" disabled="disabled" class="input">
<option value=""></option>
<option selected="selected" value="1">*DIRECT ISSUE</option>
<option value="2">*DIWELD</option>
<option value="3">*INACTIVE</option>
采纳答案by Siddharth Rout
.selectedindex
?
.selectedindex
?
The Drop down is disabled. So how do you want to get the selected item?
下拉菜单被禁用。那么你想如何获得选中的项目呢?
If you want the dropdown's inner text, try this
如果你想要下拉的内部文本,试试这个
Set drp = IE.Document.getElementById("ctl05_Dropdownlist1")
Debug.Print drp.innertext
Else if you want the innertext of a particular item say, item 1, then use this
否则,如果您想要特定项目的内部文本,例如项目 1,则使用此
drp.Item(1).innertext
FOLLOWUP FROM COMMENTS
来自评论的跟进
If you want to retrieve what is displayed currently in the disabled dropdown then use this
如果要检索禁用下拉列表中当前显示的内容,请使用此
Set drp = IE.Document.getElementById("ctl05_Dropdownlist1")
Range("J" & (ActiveCell.Row)) = drp.Item(drp.selectedIndex).innerText