VBA - Internet Automation - GetElementById.Value缺失

时间:2016-10-28 21:34:55

标签: vba internet-explorer automation getelementbyid

在线,我看到很多人完成以下代码以自动化VBA / IE搜索功能交互:

objIE.document.getElementById("id_here").Value = "Search This Text"
  • 运行此命令时收到错误“Object Required”。在ObjIE.Document之后我也失去了智能感知。

我已经研究了几个小时了,非常感谢任何帮助。这是我的完整代码。我会及时提供解决此问题所需的任何其他信息。

Sub InternetAutomation()

'Declaring and Setting Internet Explorer with Early Binding
Dim aExplorer As InternetExplorer
Set aExplorer = New InternetExplorer

'Set basic attributes of Internet Explorer and navigate to first webpage
With aExplorer
    .Visible = True
    .Navigate "www.google.com"
End With

'Wait while Internet Explorer is busy
Do While aExplorer.Busy
    Application.Wait DateAdd("s", 1, Now)
Loop

'Search Parameters
aExplorer.Document.getElementById("1st - ib").Value = "Search This Text"

End Sub

1 个答案:

答案 0 :(得分:0)

蒂姆·威廉姆斯提醒我在" getElementbyID"之后列出了我的错误ID。显然,列出一个不正确的元素会导致VBA抛出一个" Object Required"错误。

将元素更正为正确名称后,问题就解决了。

谢谢蒂姆!

关于为什么.value没有出现智能感知的任何想法?