【问题标题】:Select multiple values in a dropdown listbox on html via VBA通过VBA在html上的下拉列表框中选择多个值
【发布时间】:2017-05-12 22:52:24
【问题描述】:

问题:嘿,我正在尝试从 VBA 中选择网页下拉列表中的多个值。

select元素的HTML代码是

我设法用objIE.document.getElementsByTagName("select")(0) 选择了这个元素,因为它是整个网页上第一个标签名为“select”的元素。

如果我写objIE.document.getElementsByTagName("select")(0).Value= "E31",值“E31”将在下拉框中突出显示,没关系。

但是如何选择多个值?

我尝试了objIE.document.getElementsByTagName("select")(0).Value= "E31" + "E32"objIE.document.getElementsByTagName("select")(0).Value= "E31" & "E32",但它不起作用...

编辑:进一步尝试:我目前正在尝试使用 SendKeys 命令解决此问题,我单击列表中的一个元素,然后使用 SendKeys "+{DOWN 4}" 选择其他元素,这应该选择 4 个元素选中的第一个列表下的列表。

'objIE.document.getElementsByTagName("select")(0).Children(8).Selected = True' If I activate this line it selects (= highlight) the 9th element of the list
'objIE.document.getElementsByTagName("select")(0).Children(8).Click'if I activate this line it clicks on the 9th element of the list but doesn't highlight it
SendKeys "+{DOWN 3}"

不幸的是,这还不起作用。此外,我不知道是否有办法像here 中提到的那样以某种方式发送一个键 CTRL + MouseLeftClick,但是对于在 VBA 中无效的命令 Send

有什么想法吗?

【问题讨论】:

  • 您通过搜索发现了什么?例如,我在一分钟内找到了这个 (stackoverflow.com/questions/15191847/…)。研究是否可以使用 JavaScript 可能是一个想法。
  • 我只发现有人尝试选择 1 个值的帖子,但没有讨论如何在 VBA 编码的 html 列表中选择多个值。而且我没有看到与您提到的链接的关系。

标签: html vba drop-down-menu


【解决方案1】:

解决方案:好的,我找到了一种方法,实际上很简单。

With objIE.document.getElementsByTagName("select")(0)
    .Children(23).Selected = True
    .Children(56).Selected = True
    .Children(98).Selected = True
End With

此命令将突出显示(选择)这 3 个元素

【讨论】:

    猜你喜欢
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2021-08-04
    • 2021-12-14
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多