需要帮助,使用VBA在IE的组合框中选择多个项目 [英] Need help selecting multiple items in combobox in IE, using VBA

查看:183
本文介绍了需要帮助,使用VBA在IE的组合框中选择多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的自动化工作的一部分存在问题,那就是使用VBA和IE在网页上的组合框中选择所有选项.

I am having an issue with one part of my automation job, and that is selecting ALL the options in a combobox, on a webpage, using VBA and IE.

此代码在组合框中选择了一个项目

This code selects ONE item in the combo box

Set frm = HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
   frm.Value = "AUT"

但是,当我尝试选择多个项目时,它只会选择最后一个,而不是全部.

However, when I try to select multiple items, it just selects the last one, not all of them.

这是网页上的代码


    <p  id="DispFormCollapsible.Rc10"class="formrow" >
    <span  id="DispFormCollapsible.Rc10.C1"  class="querytextleft">
    <label for="UFG.USER_TYPES" id="LabelForContro123"class = "simpletext" >
    Accessible Types:<span class="redstar">*</span></label></span>
    <span  id="DispFormCollapsible.Rc10.C2"  class="querytextright">
    <span class="labelColumn_combo">
    <span class="labelColumn_combi_brdr"> 
    <select  name= "UFG.USER_TYPES" multiple= "true" class = "dropdownexpandalbe"
     id="UFG.USER_TYPES" title = "Accessible Financial Transaction Types"> 
    <option value="AUT"   title="ACTIVE USER TYPE1" >TYPE1</option> 
    <option value="SET"   title="Selective User Type" >TYPE2</option> 
    <option value="TST"   title="Test User Type" >TEST3</option>
    </select></span></span>
    <input type ="hidden" name= "UFG.USER_TYPES" value="NULL" >
    </span></p>

这是我的VBA行,用于选择一项

Here is my VBA line to select an item

Set frm = HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
   frm.Value = "AUT"

我需要做的是在组合框中选择所有选项值".我认为它可能需要一个数组,或者其他某种方式.我曾尝试搜索,但是却一无所获.任何帮助表示赞赏.谢谢

What I need it to do, is select all the "option values" in the combobox. I think it needs to be an array maybe, or some other way. I've tried searching, but I'm getting nowhere. Any help appreciated. Thx

尝试以下操作,但出现错误91未设置块.我还尝试过在子级中使用"AUT"值,这样做时我没有收到错误,但它没有选择任何内容.

Tried the following, but get an error 91 Block not set. I've also tried using the Values "AUT" in the children, and when doing that I don't get an error, but it doesn not select anything.

With HTMLDoc.getElementsByName("Select")(0)
    .Children(1).Selected = True
    .Children(2).Selected = True
    .Children(3).Selected = True
End With

还尝试了以下操作,这不会产生错误,而只会选择列表中的第一个选项.

Also tried the following, this doesn't give an error, but only selects the first option in the list.

With HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
    .Children(AUT).Selected = True
    .Children(SET).Selected = True
    .Children(TST).Selected = True
End With

这很奇怪,当我使用此代码时,它选择列表中的前两个,而不选择第三个.

This is strange, when I use this code, it selects the first two in the list, but not the third.

With HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
    .Children(all).Selected = True
End With

推荐答案

With HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
    .Children(0).Selected = True
    .Children(1).Selected = True
    .Children(2).Selected = True
End With

上面的代码修复了它...哎呀!

The above code fixed it... whoopie!

这篇关于需要帮助,使用VBA在IE的组合框中选择多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆