0
我需要一些幫助才能讓我的vba代碼自動登錄到網站,然後在加載的頁面上從下拉菜單中選擇一個選項。我的代碼成功登錄到網站,但它在「從下拉列表中選擇」部分不斷返回錯誤。點擊here可查看錶格元素的完整代碼,該代碼顯示我需要選擇的標籤爲「TPS Managed Balanced - Dec 11」的html代碼的結尾,該代碼的值= 303591430使用vba從Internet Explorer中的表格元素中選擇下拉列表 -
請參閱我的代碼,注意它打破了在這條線「iedoc.getElementById(‘ListPortfolio’)終值=‘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
您需要在第二頁加載時再次設置iedoc = ie.document',否則它仍然指向(現在卸載的)第一頁 –
謝謝,我在DoEvents Wend之後補充說,但我仍然得到'運行時錯誤91 - 對象變量或塊變量未設置' – chandu
我看到出了什麼問題,我需要添加更多的時間延遲,例如application.wait等待頁面加載,然後重置ioctoc。謝謝。 – chandu