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

查看:22
本文介绍了使用 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 choosing info from dropdown menus.

性别"示例:

组合框有三个选项:

Select / Male / Female

我已经尝试了一些变体:

I've tried a few variations on this:

doc.getElementsByName("xs_r_gender").Item(0).Value="Male"

...但没有运气.

这是网络源代码:

<td> <select name="xs_r_gender" id="xs_r_gender">
<option value="" selected>Select</option>
<option value="male">Male</option>
<option value="female">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)

尽管这意味着我需要进行大量查找以确定下拉列表中项目的值.(对于 Sex 来说很容易,其中只有两个选项,但我有一些组合框最多包含 50 个选项).如果有人知道更快的解决方案,那就太好了.与此同时,我会开始整理一些桌子!!!

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天全站免登陆