Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 下拉列表依赖于IE中的其他下拉列表,不更新vba_Html_Excel_Vba_Internet Explorer_Drop Down Menu - Fatal编程技术网

Html 下拉列表依赖于IE中的其他下拉列表,不更新vba

Html 下拉列表依赖于IE中的其他下拉列表,不更新vba,html,excel,vba,internet-explorer,drop-down-menu,Html,Excel,Vba,Internet Explorer,Drop Down Menu,我正在使用VBA自动化IE。我有两个下拉列表,我们称它们为A和B。B列表取决于A列表的值,所以B列表不会显示其值,除非我先手动选择A列表值。我试过这个: Sub pifa () Dim ie As Object Set ie = CreateObject("internetexplorer.application") With ie .Visible = True .n

我正在使用VBA自动化IE。我有两个下拉列表,我们称它们为A和B。B列表取决于A列表的值,所以B列表不会显示其值,除非我先手动选择A列表值。我试过这个:

 Sub pifa ()

      Dim ie As Object
      
      Set ie = CreateObject("internetexplorer.application")
      
      With ie
          .Visible = True
          .navigate "https://serviciosjava2.pifa.gob/rcel/jsp/index_bis.jsp"

           Do While .Busy
               DoEvents
           Loop

           Do While .readyState <> 4
                DoEvents
           Loop
           
                ie.document.getElementById("puntodeventa").Value = "31" 'A list value

           Do While .Busy
               DoEvents
           Loop

           Do While .readyState <> 4
                DoEvents
           Loop
           
                ie.document.getElementById("universocomprobante").Value = "19" 'B list value (doesn't work)
      
      End with

 End sub
列表代码:

<select name="puntoDeVenta" onchange="actualizarDescripcionPVConDelay(this.selectedIndex);ajaxFunction();" id="puntodeventa">
        <option value="" selected="selected" style="color:#888;" onclick=document.getElementById("desc_pto_vta").innerHTML="";>seleccionar...</option>
                        
        <option value="31">&nbsp;puntodeventaseleccionado</option>
                        
</select>
 <select name="universoComprobante" onchange="actualizarDescripcionTC(this.selectedIndex);" id="universocomprobante">
        <option value="" selected="selected" style="color:#888;">seleccionar...</option>
                        
        <option value="10">Factura A</option> 'this appears when I click manually the A list

        <option value="19">Factura B</option> 'this appears when I click manually the A list

                        
</select>
B名单代码:

<select name="puntoDeVenta" onchange="actualizarDescripcionPVConDelay(this.selectedIndex);ajaxFunction();" id="puntodeventa">
        <option value="" selected="selected" style="color:#888;" onclick=document.getElementById("desc_pto_vta").innerHTML="";>seleccionar...</option>
                        
        <option value="31">&nbsp;puntodeventaseleccionado</option>
                        
</select>
 <select name="universoComprobante" onchange="actualizarDescripcionTC(this.selectedIndex);" id="universocomprobante">
        <option value="" selected="selected" style="color:#888;">seleccionar...</option>
                        
        <option value="10">Factura A</option> 'this appears when I click manually the A list

        <option value="19">Factura B</option> 'this appears when I click manually the A list

                        
</select>

如果检查HTML代码,则可以注意到两个下拉控件都有onchange事件

Set ieEvent = htmldoc.createEvent("HTMLEvents")
ieEvent.initEvent "change", False, True
ie.document.all.Item("puntoDeVenta").dispatchEvent ieEvent
设置从VBA代码触发onchange事件所需的值后,可能有助于解决此问题

触发onchange事件的示例代码

Set ieEvent = htmldoc.createEvent("HTMLEvents")
ieEvent.initEvent "change", False, True
ie.document.all.Item("puntoDeVenta").dispatchEvent ieEvent

如果检查HTML代码,则可以注意到两个下拉控件都有onchange事件

Set ieEvent = htmldoc.createEvent("HTMLEvents")
ieEvent.initEvent "change", False, True
ie.document.all.Item("puntoDeVenta").dispatchEvent ieEvent
设置从VBA代码触发onchange事件所需的值后,可能有助于解决此问题

触发onchange事件的示例代码

Set ieEvent = htmldoc.createEvent("HTMLEvents")
ieEvent.initEvent "change", False, True
ie.document.all.Item("puntoDeVenta").dispatchEvent ieEvent

我通过在值入口下方添加以下内容解决了此问题:

 ie.document.getElementById("puntodeventa").FireEvent ("onchange")

我通过在值入口下方添加以下内容解决了此问题:

 ie.document.getElementById("puntodeventa").FireEvent ("onchange")

谢谢你的回答,这让我调查了onchange事件。我无法用你的代码解决这个问题,因为html引用对我不起作用。谢谢你的回答,它让我调查了onchange事件。我无法用你的代码解决这个问题,因为html引用对我不起作用。谢谢你发布这个问题的解决方案。我建议你试着在48小时后标记你自己对这个问题的答案。它可以在未来帮助其他社区成员解决类似的问题。感谢您的理解。感谢您发布此问题的解决方案。我建议你试着在48小时后标记你自己对这个问题的答案。它可以在未来帮助其他社区成员解决类似的问题。谢谢你的理解。