2017-04-24 79 views
0

我想指望在一個列表框中的所有元素在網頁上(最終通過他們循環,但解決這個問題將有助於循環):獲取的元素列表,從列表框中網站

enter image description here

林VBA相當新穎,但我確實相信這是一個列表框對象,因爲在這個對象的螢火蟲名稱末尾有「listbox」。

我在這裏或其他地方發現的所有建議都與.ListCount或.ListIndex相關。 不知何故,其中任何一個導致錯誤438,對象不受支持。

下面的一段代碼。 你能提出建議嗎?

With IE.document 
    .getElementById("xxx_startDay").Value = "1" 
    .getElementById("xxx_startMonth").Value = "JAN" 
    .getElementById("xxx_startYear").Value = "2017" 

    .getElementById("xxx_endDay").Value = "31" 
    .getElementById("xxx_endMonth").Value = "JAN" 
    .getElementById("xxx_endYear").Value = "2017" 

    'IE.document.getElementById("xxx_accountItemsListBox").Focus 

    Set listMPAN = IE.document.getElementById("xxx_accountItemsListBox") 

    listMPAN.selectedIndex = 5 

    MsgBox (listMPAN.ListCount) 

End With 
+0

也許你可以通過他們循環與i = 1到webList.listcount? –

+0

我一定不清楚 - .ListCount導致438錯誤。 – Pavel

回答

0

幫助比我想象的更接近。 原來ListBox中是不是真正的列表框,它是在服務器端生成的列表框與其他一些HTML元素(只是想重複我被告知):

<select size="4" name="xyz" multiple="multiple" id="xxx_accountItemsListBox" class="accountItemsListBox"> 

所以.ListCount wasnt認可。相反,我不得不使用.Length和

msgbox(listMPAN.Length) 

完美地工作。現在循環它應該很簡單。 謝謝。

+0

好!是的,它不是HTML中的列表框,通常是select元素。 –

0

這是我的備選答案:

On Error GoTo endCount 

For i = 0 To 100 
    Debug.Print myDoc2.getElementById("quoteDropdown").Item(i).Value 
Next i 



endCount: 
On Error GoTo 0 

If i <> 0 Then 

    Debug.Print "there are " & i & " options." 
End If