我真的被困在试图写一块VBA代码,真的可以使用一些帮助!我想导航到特定的网站(http://www.boxofficemojo.com/),在搜索栏中输入一个值,然后点击“搜索”。我无法让我的代码正确地按下搜索按钮。HTML搜索栏点击excel
这里是我迄今:
Dim objIE As New InternetExplorer
Dim Doc As HTMLDocument
Dim oSearch As HTMLDivElement
Dim oSearchButton As Object
Dim SearchElement As MSHTML.IHTMLElementCollection
Dim oResult As Object, Element As Object, myLink As Object
With objIE
.Visible = True
.Navigate "http://www.boxofficemojo.com/"
Do While objIE.Busy Or objIE.ReadyState <> 4
DoEvents
Loop
Set Doc = objIE.Document
End With
Set oSearch = objIE.Document.forms("searchbox").elements("q")
oSearch.Value = Sheets("2016").Range("c3").Value
Set oSearchButton = objIE.Document.forms("searchbox").getElementsByTagName("input")
objIE.Navigate oSearchButton
现在,我的代码只需导航到谷歌搜索:[对象HTMLInputElement]
的搜索按钮的HTML如下:
<form name="searchbox" action="/search/q.php" method="POST">
<input name="q" style="width: 90px; font-weight: bold;" type="text"><br>
<input type="submit" value="Search..."></form>
**<input type="submit" value="Search...">**
有谁知道我在做什么错?非常感谢你!
'getElementsByTagName'返回多个对象,并且您试图将其设置为单个对象。 – braX
与你的问题没有关系,但你不应该指objIE块中的'objIE' – jsotola