【问题标题】:Getting list of elements from web listbox从网络列表框中获取元素列表
【发布时间】:2017-09-21 07:57:50
【问题描述】:

我正在尝试计算网页上列表框中的所有元素(最终循环通过它们,但解决此问题将有助于循环):

我对 VBA 很陌生,但我相信这是一个列表框对象,因为这个对象的萤火虫名称末尾有“列表框”。

我在此处或其他地方找到的与 .ListCount 或 .ListIndex 相关的所有建议 不知何故,其中任何一个都会导致错误 438,对象不受支持。

下面的一段代码。 可以推荐一下吗?

With IE.document
  .getElementById("xxx_startDay").Value = "1"
  .getElementById("xxx_startMonth").Value = "JAN"
  .getElementById("xxx_startYear").Value = "2017"

  .getElementById("xxx_endDay").Value = "31"
  .getElementById("xxx_endMonth").Value = "JAN"
  .getElementById("xxx_endYear").Value = "2017"

  'IE.document.getElementById("xxx_accountItemsListBox").Focus

  Set listMPAN = IE.document.getElementById("xxx_accountItemsListBox")

  listMPAN.selectedIndex = 5

  MsgBox (listMPAN.ListCount)

End With

【问题讨论】:

  • 也许你可以用 for I = 1 遍历它们到 webList.listcount?
  • 我一定是不清楚 - .ListCount 导致 438 错误。

标签: excel listbox vba


【解决方案1】:

帮助比我想象的更近。 原来 ListBox 不是真正的列表框,它是在服务器端生成的其他一些带有列表框的 html 元素(只是想重复我被告知的内容):

<select size="4" name="xyz" multiple="multiple" id="xxx_accountItemsListBox" class="accountItemsListBox">

因此 .ListCount 未被识别。相反,我不得不使用 .Length 和

msgbox(listMPAN.Length)

完美运行。现在循环它应该很简单。 谢谢。

【讨论】:

  • 好!是的,它不是 HTML 中的列表框,通常是选择元素。
【解决方案2】:

这是我的替代答案:

On Error GoTo endCount

For i = 0 To 100
    Debug.Print myDoc2.getElementById("quoteDropdown").Item(i).Value
Next i



endCount:
On Error GoTo 0

If i <> 0 Then

    Debug.Print "there are  " & i & " options."
End If

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-04
    • 1970-01-01
    • 2021-01-17
    • 2014-12-16
    • 2022-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多