【问题标题】:VBA - Internet Automation - GetElementById.Value MissingVBA - 互联网自动化 - GetElementById.Value 缺失
【发布时间】: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


【解决方案1】:

Tim Williams 提醒我在“getElementbyID”之后列出的错误 ID。显然,列出不正确的元素会导致 VBA 抛出“需要对象”错误。

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

谢谢蒂姆!

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

【讨论】:

  • getElementById 可以返回任何匹配的 HTML 元素——不仅仅是输入。许多可能的元素类型没有 Value 属性...
  • 谢谢蒂姆!你非常乐于助人和善良!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-15
  • 1970-01-01
  • 2012-03-17
  • 2017-04-05
  • 2018-06-17
  • 1970-01-01
相关资源
最近更新 更多