首页 > 解决方案 > 使用 Excel VBA 将值传递给网站中的文本框

问题描述

我正在尝试浏览网站并根据 Excel 的输入执行活动。

我坚持将值传递给输入元素,该元素根据我们传递的值在下一个文本框中自动填充值(例如:如果我在目标框中传递邮政编码,则城市名称会自动填充在下一个框中)。我可以传递值,但它不会触发自动填充值的 JS。

网页中的目标框代码

<input name="zipcode" class="inputBoxRequired" id="zipcode"     onkeypress="return isNumberKey(event)" onblur="getZipCity(this.value,'/ProviderPortal')" type="text" size="46" maxlength="5">

代码尝试

Set Zip = ie_Doc.getElementById("zipcode")
 Zip.Value = Zip_Code 'Here value gets updated but associated js is not triggered
 ie_Doc.getElementById("zipcode").Focus

甚至尝试过火灾事件

Zip.FireEvent ("onchange")

在网页中,它被称为 Onkeypress 事件。我用谷歌搜索找到解决方案,但我无法得到确切的解决方案。

标签: htmlexcelvbaweb-scraping

解决方案


Zip.FireEvent ("onkeypress")
Zip.FireEvent ("onblur")  '<== Apparently this did the trick

这些是显示的事件。


推荐阅读