使用vba从表元素中选择Internet Explorer中的下拉列表 -

时间:2016-05-23 16:28:03

标签: html vba excel-vba internet-explorer automation

我需要一些帮助才能获得我的vba代码以自动登录网站,然后在加载的页面上从下拉菜单中选择一个选项。我的代码成功登录到网站,但它在“从下拉列表中选择”部分继续返回错误。点击here查看表格元素中的完整代码,该代码显示我需要在标记为“TPS Managed Balanced - Dec 11”的html代码末尾选择的选项,其值为= 303591430

到目前为止查看我的代码,注意它在此行的末尾处断开'iedoc.getElementById(“ListPortfolio”)。Value =“303591430”

Sub Strategic_Alpha_Monthly_Pivots_1_MASTER()

' open IE, navigate to the desired page and loop until fully loaded

Dim ie As Object
Dim iedoc As HTMLDocument
Dim htmlSelect As Variant

Set ie = CreateObject("InternetExplorer.Application")
my_url = "http://analytics.financialexpress.net/login.aspx"

With ie
    .Visible = True
    .navigate my_url


Do Until Not ie.Busy And ie.readyState = 4
    DoEvents
Loop

End With

' Input the userid and password
Set iedoc = ie.document
iedoc.getElementById("txtPassword").Value = "xxxx"

' Click the "Search" button
iedoc.getElementById("btnAction").Click

While ie.Busy
DoEvents
Wend


iedoc.getElementById("ListPortfolio").Value = "303591430"
iedoc.getElementById("ListPortfolio").FireEvent ("onkeypress")

End Sub

1 个答案:

答案 0 :(得分:0)

我看到出了什么问题,我需要添加更多的时间延迟,例如application.wait在重置iedoc之前等待页面加载。谢谢。