使用VBA Excel通过更改下拉列表值来浏览网站 [英] Using VBA Excel to navigate a website by changing dropdown value

查看:212
本文介绍了使用VBA Excel通过更改下拉列表值来浏览网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Excel宏,它将导航到公用事业公司网站,然后下载与该帐户相关联的所有语句。要进入语句下载页面,我需要导航到每个帐户的摘要页面。所有帐户都列在下拉列表中 - 当我从列表中手动点击其他帐户时,页面会更新到新帐户。 X-4545454545 X-454545 X-454545 X-454545 X- 20045 X-454545 X- 20045 X-454545新新新新新新新新新旗新新新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新新旗新新旗新新新旗新新新旗新新旗新新新旗新新新新旗新新新新旗新新新旗新新新新新新旗新新旗新新旗新新旗新新旗新新旗新新新新旗新新旗>这个问题,我可以让宏来改变下拉列表的值。问题是,即使从列表中选择一个新值,页面也不会更新到新帐户。不幸的是,没有直接链接到每个帐户的页面,因为下拉列表将值传递给脚本。我尝试从不同的帐户复制网址,但无论网址上的什么帐号是一样的。以下是有关VBA代码:

  Do While i< intNumberAcct 
ie.document.getElementById(ctl00_PageContent_AccountDropDown_BillingAccountsDropDown)selectedindex = i
调用downloadStatement
i = i + 1
循环
/ pre>

在更改下拉列表值后,我尝试刷新IE,但刷新后会恢复为下拉列表中的原始值。 200新X-45旗新新新新旗新新新旗新新旗新新旗新新旗新新旗新200旗200 200 200 200 200 200 200 CE 200 200 200 200 200 CE 200 200 200 200 200 200 200 CE 200 200 200 200 200 CE 200 200 200 200 200 200 200 CE 200 200 200 200 200 200 200 CE 200旗新新新新旗新新200新200新新200新新200新200新200新新200新200新新200新新200新新200新新200新200新新200新新旗200新新200新新200新新200新200新新200新新200新新200新新200新新旗200新新200新新200新新200新新200新新旗200新新200新新200新新200新新旗200新新新200新新200新新旗200 X- 2004545 X- 20045 X- 200 X- 20045 X- 200 X- 200 200 X- 200 200 X- 200 200: >

 < table style =width:100%cellpadding =0cellspacing =0> 
< tr>
< td valign =topclass =AccountDropDownLabelCellsstyle =height:25px;>
< strong>结算帐户:< / strong>
< / td>
< td valign =topstyle =text-align:leftalign =left>
< select name =ctl00 $ PageContent $ AccountDropDown $ BillingAccountsDropDownonchange =javascript:setTimeout(&#39; __ doPostBack(\&#39; ctl00 $ PageContent $ AccountDropDown $ BillingAccountsDropDown\& 200新X-454545 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045:
< option value =xxxxx> xxxxx(16 xxxxx Dr)< / option>
< option selected =xxxxxvalue =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>

在下拉列表中选择后,如何让页面更新到新帐户的任何想法200新新新新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗旗新新旗新新旗新新旗新新旗旗新新旗新新旗新新旗旗新1992新新新新旗新1992 200新新新新旗新新旗200新新新新旗新新旗200新新新旗新1992新新新新旗新1992新新旗新1992 200新新新旗新1992:
$ b


select name =ctl00 $ PageContent $ AccountDropDown $ BillingAccountsDropDown onchange =javascript:setTimeout('__ doPostBack(\'ctl00 $ PageContent $ AccountDropDown $ BillingAccountsDropDown\'','\\''''',0) id =ctl00_PageContent_AccountDropDown_BillingAccountsDropDownstyle =width:250px;



X-454545454545 X- 20045 X-45454545 X- 20045 X-454545 X-454545新新新新旗新新新新旗新新新新旗新新新新旗新新旗新新新旗新新旗新新旗新新新新旗新新旗2001-新新新新旗新新旗2001-新新新新新新旗新新旗2001-新新新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新旗新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新旗新旗新旗新b


I am writing an Excel macro that will navigate to a utility company website and then download all of the statements linked to that account. To get to the statement download page, I need to navigate to each account's summary page. All of the accounts are listed in a dropdown - when I manually click a different account from the list, the page updates to the new account. Using the tip I got from this question, I am able to get the macro to change the dropdown value. The problem is, even though it chooses a new value from the list, the page doesn't update to the new account. Unfortunately, there is no direct link to each account's page as it looks like the dropdown passes a value to a script. I tried copying the URL down from different accounts, but no matter what account it's on the URL is the same. Here is VBA code in question:

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

I tried refreshing IE after it changes the dropdown value, but when it refreshes it reverts back to the original value in the dropdown. I also tried ie.document.getElementById("ctl00_PageContent_AccountDropDown_BillingAccountsDropDown").Click after it selected the new index, but it didn't have any effect.

Here is the html source code of the dropdown - I removed a large chunk of the accounts so it wouldn't be so long and obfuscated the account numbers and addresses with '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>

Any ideas on how to get the page to update to the new account after selecting it in the dropdown would be greatly appreciated.

解决方案

Once you set the index of dropdown you need to trigger the change event.

select name="ctl00$PageContent$AccountDropDown$BillingAccountsDropDown" onchange="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$AccountDropDown$BillingAccountsDropDown\',\'\')', 0)" id="ctl00_PageContent_AccountDropDown_BillingAccountsDropDown" style="width:250px;"

doc.getElementById("xs_r_gender").selectedindex=1
doc.getElementById("xs_r_gender").FireEvent("onchange")

这篇关于使用VBA Excel通过更改下拉列表值来浏览网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆