[英]Export IE report to excel using VBA where export drop down menu exists
[英]Need to automate IE with drop down menu using Excel VBA
我要自動化一個站點,該站點具有一個名為“時間表”的下拉菜單,然后單擊菜單項“項目”,該菜單項在列表中位於第3位。
這是HTML代碼:
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" ng-click="$event.preventDefault()" title="Timesheet" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-time"></span> Timesheet <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a ui-sref="AddTime" title="Add time" href="/Timesheet/AddTime/">Add time</a></li>
<li><a ui-sref="ApproveTime" title="Approve time" href="/Timesheet/ApproveTime">Approve time</a></li>
<li><a ui-sref="Projects" title="Projects" href="/Timesheet/Admin/Projects">Projects</a></li>
<li><a ui-sref="BudgetCode" title="Budget Code" href="/Timesheet/Admin/BudgetCode">Budget Code</a></li>
<li><a ui-sref="WorkCode" title="Work Code" href="/Timesheet/Admin/WorkCode">Work Code</a></li>
<li><a ui-sref="Functions" title="Functions" href="/Timesheet/Admin/Functions">Functions</a></li>
<li><a ui-sref="WorkStreams" title="Work Streams" href="/Timesheet/Admin/WorkStreams">Work Streams</a></li>
<li><a ui-sref="EmployeeResource" title="Employees" href="/Timesheet/Admin/EmployeeResource">Employees</a></li>
</ul>
</li>
</ul>
</div>
VBA代碼:私有Sub IE_Test()昏暗i作為長暗IE作為對象暗ElementCol作為對象
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
'IE.Visible = False
IE.Navigate "http://st-toss/"
' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
IE.Visible = True
Set ElementCol = IE.Document.getElementsByClassName("dropdown-menu")
ElementCol.Item(2).Click
' Clean up
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
Application.StatusBar = ""
結束子
我嘗試按類名/標記名進行選擇,但是一旦我未添加任何斷點,就會遇到相同的錯誤自動化錯誤/未指定錯誤。 一旦我將斷點放在get方法上,錯誤消息就會說調用的對象與客戶端斷開了連接。
請提出我該如何解決。
ElementCol是“下拉菜單”類中的元素的集合。 (您在設置getElementsByClassName時創建了此集合。請注意,“ Elements”是復數。)
該類中有多少個元素,您需要哪一個?
如果這是該類中的唯一元素,則可以通過以下方式引用它:
elementCol(0).selectedIndex = 2
或類似的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.