用VBA填写网站表格中的下拉菜单。

问题描述 投票:1回答:1

在Excel中编写以下VBA宏。

Sub compile()

Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")

IE.Navigate "www.google.it"
IE.Visible = True

Do While IE.Busy
    DoEvents
Loop

IE.document.getElementById("Civico").Value = "1"

End Sub

"房号 "字段没有填写,我真的不知道怎么填写。谁能帮帮我?谢谢!

excel vba internet-explorer-11
1个回答
0
投票

我认为你不能选择下拉列表的值,因为它没有被初始化。我们需要从 "VCinputLoc "中选择值,这样 "VCinputCivico "的下拉列表才会显示。你可以模拟按键而不是设置值,并在代码中增加一些等待下拉列表初始化的时间。

代码示例。

Sub compile()

Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")

IE.Navigate "https://fibra.planetel.it"
IE.Visible = True

Do While IE.Busy
    DoEvents
Loop

IE.document.getElementById("VCinputLoc").Focus
IE.document.getElementById("VCinputLoc").Value = "ROMA"
Application.SendKeys "{ENTER}"
Application.Wait (Now + TimeValue("00:00:02"))
IE.document.getElementsByClassName("autocomplete-suggestion")(0).Click
IE.document.getElementById("VCinputIndirizzo").Focus
IE.document.getElementById("VCinputIndirizzo").Value = "Piazza Del Campidoglio"
Application.Wait (Now + TimeValue("00:00:05"))
IE.document.getElementById("VCinputCivico_chosen").getElementsByTagName("a")(0).Focus
Application.SendKeys "{DOWN}"
Application.SendKeys "1"
Application.SendKeys "{DOWN}"
Application.SendKeys "{ENTER}" 'the last step can't enter the value, you could research more and I'll also continue to research
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.