【发布时间】:2016-10-28 21:34:55
【问题描述】:
在网上,我看到很多人完成以下代码来自动化 VBA/IE 搜索功能交互:
objIE.document.getElementById("id_here").Value = "Search This Text"
- 运行此程序时收到错误“需要对象”。 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
【问题讨论】:
-
id 值为 "lst-ib" ,而不是 "1st - ib"
-
谢谢!仍然有同样的问题。有什么想法吗?
-
对 id 的更改对我有用
-
非常感谢蒂姆!它现在也适用于我。显然,当 .getElementById 的 id 不正确时,会发生“需要对象”错误。
标签: vba internet-explorer automation getelementbyid