【问题标题】:Method 'frames' of object 'JScriptTypeInfo' failed对象“JScriptTypeInfo”的方法“框架”失败
【发布时间】:2014-10-13 19:16:13
【问题描述】:

我正在通过 excel VBA 实现 Internet Explorer 9 的自动化,当我到达下面的最后一行时,它会引发错误:

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "https://example.com/Main.asp"

'delay till readystate is complete

Set doc = ie.document
Set doc1 = doc.frames(2).document 'here comes the error

有人可以帮忙吗?

【问题讨论】:

  • 去掉多余的Set ie = New InternetExplorer,在.navigate后面加上Do Until IE.ReadyState = 4: DoEvents: Loop。尝试使用 F12 在网页内容中手动查找必要的框架。
  • 网页上确实有框架。我用 F12 进行了检查

标签: vba internet-explorer excel frames comexception


【解决方案1】:

我也遇到了同样的问题,已经解决了

这适用于 IE 10+

设置 doc = ie.document.frames

设置 doc1 = doc.frames(2)

对于脚本元素,不再支持 readyState。从 Internet Explorer 11 开始,使用 onload

IE 11 has different ways to access attributes

【讨论】:

    【解决方案2】:

    在迁移到 IE11 后,我在使用一些 Excel VBA 代码时遇到了同样的问题。这是我必须做的修复它:

    在 IE8 中工作但在 IE11 中抛出错误的旧代码

    Set objCollection = IE.Document.frames(0).Document.getElementsByTagName("span")
    

    适用于 IE11 的新代码 (我必须在工具/引用下添加对 Microsoft HTML 对象库的引用)

    Dim htmlDoc As MSHTML.HTMLDocument
    Dim htmlWindow As MSHTML.HTMLWindow2
    Set htmlDoc = IE.Document
    Set htmlWindow = htmlDoc.frames(0)
    Set objCollection = htmlWindow.Document.getElementsByTagName("span")
    

    【讨论】:

    • 谢谢,这段代码有效吗?它给出了“拒绝访问”错误
    猜你喜欢
    • 2017-04-02
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    相关资源
    最近更新 更多