我如何从组合框中选择数据并使用VBA-excel触发onchange命令

时间:2019-02-12 20:14:58

标签: excel vba internet-explorer web-scraping

我想在组合框中选择“ 56-Hoyer(Suk / Rontec)”,然后使用VBA excel触发重新加载页面的事件,我可以将文本放在组合框中,但是不会加载javascript附加到它(onchange事件)。

see image of the drop down / combo box here

下面的

是我在VBA中使用的代码,用于以恒定值填充组合框。但是我无法在提供的html上运行onchange事件。

Call IE.document.getElementById("orders.carrier_number_txtSelectionDisplay").setAttribute("value", "56 - Hoyer (Suk / Rontec)")
Call IE.document.getElementById("orders.carrier_number_txtSelectionDisplay").setAttribute("value", "56 - Hoyer (Suk / Rontec)")

Set x = IE.document.getElementById(orders.carrier_number_txtSelectedValue)
       x.Focus
       x.FireEvent "onchange"

下面是HTML代码:

<td>
<div>
    <span id="Descriptor.orders.carrier_number" class="dataentry-descriptor dataentry-descriptor-top" style="text-align:left;">Carrier</span>
</div>
    <div class="dataentry-field-control" style="text-align:left;">
        <div id="orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b" timerid="" querymethodname="GetSupplierCarriers">
            <div id="orders.carrier_number_pnlSelectionDisplay" class="ffnet-combo-box dataentry-field required" style="width:180px;">
                <table border="0" style="border-spacing: 0px; border-collapse: collapse; margin:0px;">
                    <colgroup>
                        <col style="width: 100%"> 
                        <col style="width: 30px; text-align: right;"> 
                    </colgroup> 
                    <tbody>
                        <tr>
                            <td style="padding: 0px;">
                                <input name="orders.carrier_number$txtSelectionDisplay" type="text" id="orders.carrier_number_txtSelectionDisplay" class="dataentry-field required  validate[required] required" isrequired="True" datatype="3"
                                onkeydown="javascript:return InputProcessKeyDown('orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b', event);" onfocus="javascript:return InputProcessOnFocus('orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b');
                                " style="width:150px;"> 
                                <input name="orders.carrier_number$txtSelectedValue" type="text" onchange="retrieveChildData(&quot;orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b&quot;,&quot;orders.loaded_driver_number_e5ba36ca-
                                aa0f-4f55-aa3e-c7cb342d0b0b&quot;); retrieveChildData(&quot;orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b&quot;,&quot;orders.delivered_driver_number_e7747c68-df71-4774-9b04-
                                d897d1fd9833&quot;); retrieveChildData(&quot;orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b&quot;,&quot;orders.vehicle_code_d3cc805c-e505-45c5-a351-98028439e34d&quot;); retrieveChildData(&quot;orders.carrier_number_4b7bc829-
                                2760-4042-aab0-be8ccfb9541b&quot;,&quot;orders.tractor_number_089faa52-6810-4815-8f64-81eb201105a2&quot;); UpdateDirtyBit(1);setTimeout('__doPostBack(\'orders.carrier_number$txtSelectedValue\',\'\')', 0)"
                                onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="orders.carrier_number_txtSelectedValue" datavaluefield="carrier_number" assembly="FFNET_CORE" funcname="OrderDispatch_DeleteOrderTrailer"
                                methodclass="CBL" hasautopostback="true" namespace="FBS" selectlistargs="{&quot;SenderId&quot;:&quot;orders.carrier_number&quot;,&quot;supplier_number&quot;:&quot;139&quot;,&quot;RequiresParent&quot;:&quot;True&quot;}" style="display:none;">
                            </td>
                            <td> 
                                <img id="orders.carrier_number_imgArrow" onclick="InputProcessOnFocus('orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b'); activeCB.toggleDropDown();" src="/ffnet/Images/DropDownListArrow.gif">
                            </td>
                        </tr> 
                    </tbody>
                </table>
            </div>

            <div id="orders.carrier_number_pnlDropDownList" class="ffnet-combo-box-ddlist" style="width:339px;">
                <div id="orders.carrier_number_pnlDropDownRegion" class="ffnet-combo-box-ddregion" value="" style="width:339px;">
                    <table header="0" style="width:322px;" cellspacing="0" cellpadding="0">
                        <colgroup>
                            <col style="width:80px;">
                            <col style="width:210px;">
                        </colgroup>
                        <tbody>
                            <tr> 
                                <th>Carrier Number</th>
                                <th>Name</th> 
                            </tr>
                        </tbody>
                    </table>
                <div id="orders.carrier_number_pnlDataRegion" class="ffnet-combo-box-data" style="width:339px;height:200px;">
                    <table style="width:322px;" onkeydown="javascript:return ProcessKeyDown(this, event);" tabindex="0" mode="combobox">
                        <colgroup>
                            <col style="width:80px;">
                            <col style="width:210px;">
                        </colgroup>
                        <tbody>
                            <tr id="orders.carrier_number_tr0" pk="1" text="1 - Armac Shipping" class="ffnet-combo-box-row-focus">
                                <td>1</td>
                                <td>Armac Shipping</td>
                            </tr>
                            <tr id="orders.carrier_number_tr1" pk="2" text="2 - IPCS Ltd">
                                <td>2</td>
                                <td>IPCS Ltd</td>
                            </tr>                       
                            <tr id="orders.carrier_number_tr23" pk="56" text="56 - Hoyer (Suk / Rontec)">
                                <td>56</td>
                                <td>Hoyer (Suk / Rontec)</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div id="orders.carrier_number_pnlPager" class="ffnet-combo-box-paging" title="Click for more records" onclick="RetrieveNextPage($(&quot;[id$='orders.carrier_number_4b7bc829-2760-4042-aab0-be8ccfb9541b']&quot;).get(0), false);
                " recordcount="129">

    1-30 of 129 results
                </div> 
            </div> 
        </div> 
    </div>
    <input type="hidden" name="orders.carrier_number_txtSelectedValue_hdnDirtyBit" id="orders.carrier_number_txtSelectedValue_hdnDirtyBit" value="0">
</div>

0 个答案:

没有答案