3

我正在编写一个 Excel 宏,它将导航到公用事业公司网站,然后下载链接到该帐户的所有报表。要访问报表下载页面,我需要导航到每个帐户的摘要页面。所有帐户都列在下拉列表中 - 当我从列表中手动单击其他帐户时,页面会更新为新帐户。使用我从这个问题中得到的提示,我可以获取宏来更改下拉值。问题是,即使它从列表中选择了一个新值,页面也不会更新到新帐户。不幸的是,没有直接链接到每个帐户的页面,因为看起来下拉菜单将值传递给脚本。我尝试从不同的帐户复制 URL,但无论 URL 上的哪个帐户都是相同的。这是有问题的VBA代码:

Do While i < intNumberAcct
    ie.document.getElementById("ctl00_PageContent_AccountDropDown_BillingAccountsDropDown").selectedindex = i
    Call downloadStatement
    i = i + 1
Loop

我在更改下拉列表值后尝试刷新 IE,但是当它刷新时,它会恢复为下拉列表中的原始值。在它选择新索引后我也尝试过ie.document.getElementById("ctl00_PageContent_AccountDropDown_BillingAccountsDropDown").Click,但没有任何效果。

这是下拉列表的 html 源代码 - 我删除了一大块帐户,因此它不会太长,并用“x”混淆了帐号和地址:

<table style="width: 100%" cellpadding="0" cellspacing="0">
<tr>
    <td valign="top" class="AccountDropDownLabelCells" style="height: 25px;">
        <strong>Billing Account:</strong>
    </td>
    <td valign="top" style="text-align: left" align="left">
        <select name="ctl00$PageContent$AccountDropDown$BillingAccountsDropDown" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;ctl00$PageContent$AccountDropDown$BillingAccountsDropDown\&#39;,\&#39;\&#39;)&#39;, 0)" id="ctl00_PageContent_AccountDropDown_BillingAccountsDropDown" style="width:250px;">
          <option value="xxxxx">xxxxx(16 xxxxx Dr)</option>
          <option selected="xxxxx" value="xxxxx">xxxxx(18 xxxxxDr)</option>
          <option value="xxxxx">xxxxx(20 xxxxx Dr)</option>
          <option value="xxxxx">xxxxx(22 xxxxxDr)</option>
          <option value="xxxxx">xxxxx(28 xxxxx Dr)</option>
          <option value="xxxxx">xxxxx(30 xxxxxDr)</option>
          <option value="xxxxx">xxxxx(34 xxxxxDr)</option>
</select>
        &nbsp;
    </td>
</tr>


</table>

在下拉列表中选择页面后如何让页面更新到新帐户的任何想法将不胜感激。

4

1 回答 1

3

设置下拉列表的索引后,您需要触发更改事件。

select name="ctl00$PageContent$AccountDropDown$BillingAccountsDropDown" onchange="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$AccountDropDown$BillingAccountsDropDown\',\'\')', 0)" id="ctl00_PageContent_AccountDropDown_BillingAccountsDropDown" 样式="宽度:250像素;"

doc.getElementById("xs_r_gender").selectedindex=1
doc.getElementById("xs_r_gender").FireEvent("onchange")
于 2013-05-03T00:45:36.110 回答