VBAselect下拉菜单网站

我目前正在尝试用vba写一些东西来访问一个网站,并从表中获取信息。 到目前为止,我只设法login并导航到表格,但是现在我想要做的是首先过滤表格,方法是在下拉菜单中select不同的选项。

下面是我的代码:

 Sub browse() Set objIE = CreateObject("InternetExplorer.Application") WebSite = "https://www.kicktipp.de/info/profil/login" With objIE .Visible = True .navigate WebSite Do While .Busy Or .ReadyState <> 4 DoEvents Loop Set Element = .document.getElementsByName("kennung") Element.Item(0).Value = "myemail" Set Element = .document.getElementsByName("passwort") Element.Item(0).Value = "password" .document.forms(0).submit .navigate "https://www.kicktipp.de/los-bwlos/gesamtuebersicht" While ie.ReadyState <> 4 Or ie.Busy: DoEvents: Wend Set Element = .document.getElementById("tippspieltagVonIndex") Element.Item(0).Value = 4 Element.FireEvent ("onchange") Application.SendKeys (Enter) End With End Sub 

问题是,当我尝试select下拉菜单时,根据使用getElementByIdgetElementsbyName ,我得到不同的错误信息。

下面是该部分的HTML:

 <tr class="e"> <td class="nw"> <div><label for="tippspieltagVonIndex">Spieltage</label> </div></td><td><b>von</b> <select name="tippspieltagVonIndex" id="tippspieltagVonIndex"> <option selected="selected" value="1">1. Spieltag</option> <option value="2">2. Spieltag</option> <option value="3">3. Spieltag</option> <option value="4">4. Spieltag</option> <option value="5">5. Spieltag</option> <option value="6">Achtelfinale</option> <option value="7">Viertelfinale</option> <option value="8">Halbfinale</option> 

SelectedIndex属性

而不是Element.Item(0).Value = 4
试试: Element.Item(0).selectedIndex = 4

在扩展login网站HTML上工作的代码

我无法login,所以我将Select标签添加到login网站。 下面的代码中的每个选项都适用于我。

 Sub browse() Dim objIE As Object Dim Element As Object Set objIE = CreateObject("InternetExplorer.Application") With objIE .Visible = True .navigate "https://www.kicktipp.de/info/profil/login" Do While .Busy Or .ReadyState <> 4 DoEvents Loop 'element copied from your question, pasted into the login site HTML Set Element = .document.getElementById("tippspieltagVonIndex") 'any option below did change the select element Element.Value = 1 '1. Spieltag Element.Value = "2" '2. Spieltag Element.selectedIndex= 2 '3. Spieltag because 0-based array .Quit End With 'objIE End Sub