需要使用Excel VBA下拉菜单自动化IE [英] Need to automate IE with drop down menu using Excel VBA

查看:267
本文介绍了需要使用Excel VBA下拉菜单自动化IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望自动化一个名为Timesheet的下拉菜单的网站,然后点击列表中第3个菜单项项目。

I want to automate a site having drop down menu named 'Timesheet' and then click on the Menu item 'Project' which is 3rd in the list.

以下是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代码:
私人子IE_Test()
Dim i As Long
Dim IE As Object
Dim ElementCol As Object

VBA code: Private Sub IE_Test() Dim i As Long Dim IE As Object Dim ElementCol As Object

' 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 = ""

End Sub

我尝试按类名/标记名选择,但我一直在一旦我没有添加任何断点,同样的错误自动化错误/未指定的错误。一旦我把断点放在get方法错误消息上,就说调用的对象与客户端断开连接。

I have tried selecting by classname/tagname but I have been getting the same error Automation error/Unspecified error once i did not add any break point. And once i put the breakpoint on the get method error message says object invoked disconnected from client.

请建议我如何解决这个问题。

Please suggest how can i get through this.

推荐答案

ElementCol是元素的集合在课程下拉菜单中。 (您在设置getElementsByClassName时创建了此集合。请注意,Elements是复数。)

ElementCol is a collection of elements in the class "dropdown-menu". (You created this collection when you set getElementsByClassName. Notice that "Elements" is plural.)

该类中有多少个元素,哪一个是你的元素需要?

如果这是该类中唯一的元素,那么你可以通过以下方式引用它:

How many elements are there in that class, and which one is the one you need?
If this is the only element in that class, then you would refer to it by :

elementCol(0).selectedIndex = 2

或类似的东西。

这篇关于需要使用Excel VBA下拉菜单自动化IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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