我在具有相关组合框的网站上有此表单。
当通过vba更新第一个组合框(状态)时,第二个组合框(自治市)需要填充您的列表。
我试过这种方式:
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "http://www2.correios.com.br/sistemas/agencias/"
Do Until (ie.ReadyState = 4)
Loop
'First combobox
ie.Document.all("estadoAgencia").Item(2).Selected = True
ie.Document.all("estadoAgencia").Item(2).Focus
ie.Document.all("estadoAgencia").Item(2).Click
ie.Document.all("estadoAgencia").Item(2).FireEvent ("onChange")
'Second combobox
ie.Document.all("municipioAgencia").Item(2).Selected = True 'Do not work here, this last line
我想我必须使用该方法调用一些函数: ie.Document.parentWindow.execScript(" functionname()")
但是我找不到要在这行中调用的函数。
<script type="text/javascript">/* <![CDATA[ */
var _cf_cfcAgencia=ColdFusion.AjaxProxy.init('/sistemas/agencias/cfc/cfcAgencia.cfc','ProxyAjax');
_cf_cfcAgencia.prototype.getAgenciasProximas=function(latitude,longitude) { return ColdFusion.AjaxProxy.invoke(this, "getAgenciasProximas","45A0BE8C97B5F00E", {latitude:latitude,longitude:longitude});};
_cf_cfcAgencia.prototype.getBairro=function(UF,municipio) { return ColdFusion.AjaxProxy.invoke(this, "getBairro","45A0BE8C97B5F00E", {UF:UF,municipio:municipio});};
_cf_cfcAgencia.prototype.getUF=function() { return ColdFusion.AjaxProxy.invoke(this, "getUF","45A0BE8C97B5F00E", {});};
_cf_cfcAgencia.prototype.getMunicipio=function(UF) { return ColdFusion.AjaxProxy.invoke(this, "getMunicipio","45A0BE8C97B5F00E", {UF:UF});};
/* ]]> */</script>
我相信可以:
_cf_cfcAgencia.prototype.getMunicipio=function(UF)
有人可以帮助我吗?
答案 0 :(得分:0)
我在IE8及更早版本中工作了很多,但是使用IE9 +似乎有一些变化。我们必须使用dispatchEvent()
以不同的方式连接事件。
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://www2.correios.com.br/sistemas/agencias/"
Do Until (ie.ReadyState = 4)
Loop
'First combobox
' ie.document.all("estadoAgencia").Item(2).Selected = True
' ie.document.all("estadoAgencia").Item(2).Focus
' ie.document.all("estadoAgencia").Item(2).Click
' ie.document.all("estadoAgencia").Item(2).FireEvent ("onkeypress")
Set evt = ie.document.createevent("htmlevents")
evt.initevent "change", True, False
Set lst = ie.document.getelementbyid("estadoAgencia")
lst.selectedindex = 2 'select it as you were
lst.dispatchevent evt 'Fire the event with dispatchEvent
'Second combobox
ie.document.all("municipioAgencia").Item(2).Selected = True