搜索错误,自动化错误

时间:2018-03-23 08:55:36

标签: vba excel-vba excel

我已经知道了一些代码可以从单元格中提取信息并将其粘贴到搜索引擎中进行搜索。这在谷歌和bing上都经过测试可以正常工作,可以恢复我想要搜索的内容。

现在我已经将我认为正确的代码更改为内部网站,但现在却出现了运行时错误和自动化错误。它会加载网站,只是不搜索它。

我没有这方面的专家所以仍然在努力学习VBA。此外,如果你可以建议任何关于解决问题的最佳方法的指针。

目前,我弄清楚的唯一方法是打破每一行,看看它做了什么并发现了错误。但这有点超出我的意义。

我认为唯一可能但可能是错误的是缺少参考

我已经获得了HTML对象库和Internet控件。

Run time error

这是搜索框网站的代码。

<input class="genInput" type="text" size="32" name="xx_quicksearch" value="" id="quicksearchbox">

这是我的代码,

Sub Test()
Dim ie As Object
Dim form As Variant
Dim button As Variant
Dim LR As Integer
Dim var As String
LR = Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To LR
var = Cells(x, 1).Value
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
With ie
.Visible = True
.navigate "*******"
While Not .readyState = READYSTATE_COMPLETE
Wend
End With
'Wait some to time for loading the page
 While ie.Busy
 DoEvents
Wend
Application.Wait (Now + TimeValue("0:00:02"))
ie.document.getElementById("quicksearch").Value = var
'code to click the button
 Set form = ie.document.getElementsByTagName("form")
 Application.Wait (Now + TimeValue("0:00:02"))
 Set button = form(0).onsubmit
 form(0).submit
 'wait for page to load
While ie.Busy
DoEvents
Wend
Next x
End Sub

1 个答案:

答案 0 :(得分:0)

ID与您发布的内容不同。在:ie.document.getElementById("quicksearch").Value = var尝试输入"quicksearchbox"而不仅仅是"quicksearch"