使用excel vba更改网站上的下拉菜单的值 [英] Using excel vba to change the value of a dropdown menu on a website

查看:906
本文介绍了使用excel vba更改网站上的下拉菜单的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个excel宏来填写网站上的表单。我编写的代码填充文本框很容易,并发现代码选择广播框,但我有从下拉菜单中选择信息的问题。例如。性别。
组合框有三个选项。选择/男/女。

I am writing an excel macro to fill out a form on a website. I have written the code that populate the text boxes easily enough, and found code to chose radio boxes, but I am having problems with chosing info from dropdown menus. eg. Gender. The combo box has three options. Select / Male / Female.

Ive尝试了一些变化:
doc.getElementsByName(xs_r_gender)。Item(0).value =男性

Ive tried a few variations on this: doc.getElementsByName("xs_r_gender").Item(0).value="Male"

但没有运气。
这是网络源代码:

but with no luck. This is the web source code:

< td> < select name =xs_r_genderid =xs_r_gender>
< option value =selected>选择< / option>
< option value =male>男性< / option>
< option value =female>女性< / option> < / select>< / td>

感谢

推荐答案

doc.getElementById(xs_r_gender)。selectedindex = 1

似乎做到了。 (其中1代表男性)

doc.getElementById("xs_r_gender").selectedindex=1
seems to do the trick. (Where 1 represents male)

虽然这意味着我需要做很多查找,以确定我的下拉菜单中的项目的值。 (很容易为性,其中只有两个选项,但我有一些组合框与多达50个选项)。如果有人知道更快的解决方案,那将是巨大的。在此期间,Ill开始做一些表格。

Though it means I will need to do alot of lookups to determine what the value is for the items in my dropdown. (Easy enough for Sex, where there are only two options, but I have some comboboxes with up to 50 options). If anyone knows of a faster solution, that'd be great. In the meantime, Ill start doing up some tables!!!

感谢。

这篇关于使用excel vba更改网站上的下拉菜单的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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