2

I have this form on a site with dependent combobox.

When updating the first combobox (state) through vba, the second combobox (municipality) need to populate your list.

I've tried this way:

 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

I think I have to call some function using the method: ie.Document.parentWindow.execScript ("functionname()")

But I could not find the function to call in this lines.

<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>

I believe that can be:

  _cf_cfcAgencia.prototype.getMunicipio=function(UF)

Somebody can help me?

Community
  • 1
  • 1

1 Answers1

0

I worked a lot with IE8 and earlier, but with IE9+ it seems there's been some changes. We have to hook up to the events differently using 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

See this question for further reference

Community
  • 1
  • 1
Jimmy Smith
  • 2,452
  • 1
  • 16
  • 19