【问题标题】:Web Automation using Excel VBA使用 Excel VBA 实现 Web 自动化
【发布时间】:2017-06-03 09:10:56
【问题描述】:

我尝试自动化一些登录并将网络上的粘贴复制到我自己的机器上。当我从公司的 Intranet 尝试相同的事情时,我遇到了问题。我的错误信息是:

对象变量或未设置块变量。

这是我的代码:

Sub getdata()
Dim IE As Object
Dim Doc As HTMLDocument
Dim naziv, test, test2 As Variant

'Set IE = CreateObject("InternetExplorer.Application")
Set IE = New InternetExplorerMedium

IE.Visible = True

IE.navigate "https://example.com/Pages/default.aspx"

Do While IE.readyState = 4
DoEvents
Loop

Set test = Doc
Set test2 = Doc

test2 = test.getElementById("testid")

MsgBox (test2.innerText)

End Sub

【问题讨论】:

  • 你还没有初始化你的Doc变量。

标签: html vba excel internet-explorer


【解决方案1】:

去掉下面两行

Set test = Doc
Set test2 = Doc

先设置doc变量

Set Doc = IE.document

然后设置test2对象

set test2 = Doc.getElementById("testid")

【讨论】:

  • '--> Set test2 = Doc.getElementById("testid") :)
  • @SiddharthRout 感谢您的更正。我忘了补充。 :)
  • ++ 别担心,我有时也会想念一些小事:)
  • 再次感谢。 :)
  • 非常感谢您的快速帮助,现在我收到另一条错误消息:对象“IWebBrowser2”的方法“文档”失败。我无法想象我该如何解决这个问题,我在 1 周前尝试过...谢谢你,如果你能添加一些问题:)。
猜你喜欢
  • 2016-10-10
  • 1970-01-01
  • 2021-09-28
  • 2020-01-09
  • 2017-11-29
  • 2018-11-06
  • 1970-01-01
  • 2013-02-13
  • 2012-01-10
相关资源
最近更新 更多