IE和Excel VBA - 从下拉列表中选择项目

时间:2017-07-06 06:28:23

标签: excel vba excel-vba internet-explorer

我想登录网页,但是我没有成功,也找不到任何有用的教程,说明或建议。在这个页面上:https://emir.palyazat.gov.hu/nd/eupalyazat/index.php?tip=100009&opid=9#login_jelzo我想从列表“GOP-2.1.3-11”(值:1950)中选择,然后会出现另一个(以前隐藏的)列表。从这个列表中我必须选择GOP-2.1.3-11-2011-0085(价值:74347)。在第一步,我遇到了以下代码:

Sub IEopen()

Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLButtons As MSHTML.IHTMLElementCollection
Dim HTMLButton As MSHTML.IHTMLElement
Dim HTMLTable As MSHTML.IHTMLElement
Dim HTMLTables As MSHTML.IHTMLElementCollection
Dim HTMLRow As MSHTML.IHTMLElement

IE.Visible = True
IE.Navigate "https://emir.palyazat.gov.hu/nd/eupalyazat/index.php?tip=100009&opid=9#login_jelzo"

Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop

Set HTMLDoc = IE.Document

Set HTMLRow = HTMLDoc.getElementById("id_paly_altip")
HTMLRow.Value = "1950"
End Sub

我必须在该页面上管理更多帐户,点击按钮即可轻松登录。

参考:Microsoft Internet Control,Microsoft HTML Object Library,Microsoft xml,v6.0和Microsoft_Jscript。

感谢您的帮助,如果您有关于在VBA中处理网页的全面说明,请将其粘贴到您的答案中。非常感谢你。

1 个答案:

答案 0 :(得分:0)

我不得不使用application.sendkeys,但最后它成功了:

Set HTMLRow = HTMLDoc.getElementById("id_paly_altip")
HTMLRow.Value = "XXXXXXXXXXX"
Application.SendKeys ("{up}")
Application.Wait (Now + TimeValue("0:00:01"))
Application.SendKeys ("{down}")
Application.Wait (Now + TimeValue("0:00:01"))

Application.SendKeys ("{tab}")

Set HTMLRow = HTMLDoc.getElementById("palyazat_szama")
HTMLRow.Value = "XXXXXXXXXXXXX"
Application.SendKeys ("{up}")
Application.Wait (Now + TimeValue("0:00:01"))
Application.SendKeys ("{down}")
Application.Wait (Now + TimeValue("0:00:01"))

Set HTMLRow = HTMLDoc.getElementById("lb_felhasznalo")
HTMLRow.Value = "XXXXXXXXXXXXXXXX"

Application.SendKeys ("{tab 2}")
Application.SendKeys ("XXXXXXXXXXXXXXXXXXXXXXX")

Application.Wait (Now + TimeValue("0:00:01"))

Set HTMLButton = HTMLDoc.getElementById("login_submit")
HTMLButton.disabled = ""
HTMLButton.Click

Application.SendKeys "{NUMLOCK}%s"

End Sub

但是,我没有找到有关IE和VBA的任何全面描述。你能推荐一个吗? THX