首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对象iwebbrowser2的方法文档失败

对象iwebbrowser2的方法文档失败
EN

Stack Overflow用户
提问于 2016-09-14 16:53:03
回答 1查看 4.5K关注 0票数 0

我收到这个错误"method document of object iwebbrowser2 failed“。请看下面的代码。

代码语言:javascript
复制
Sub getIE()
Dim sh As Object, oWin As Object, IE As Object

Set sh = CreateObject("Shell.Application")

For Each oWin In sh.Windows
    If TypeName(oWin.document) = "HTMLDocument" Then
        Set IE = oWin
        Exit For
    End If
Next

MsgBox IE.document.URL

End Sub
EN

回答 1

Stack Overflow用户

发布于 2016-09-14 17:42:53

首先,确保您已在Internet Explorer上打开了一个站点。然后运行代码。我没有得到和你一样的错误,但是得到了对象引用错误。因此,在对象为nothing时添加了检查。

代码语言:javascript
复制
Sub getIE()
  Dim sh As Object, oWin As Object, IE As Object

  Set sh = CreateObject("Shell.Application")

  For Each oWin In sh.Windows
    If TypeName(oWin.document) = "HTMLDocument" Then
        Set IE = oWin
        Exit For
    End If
  Next

  If Not IE Is Nothing Then
    MsgBox IE.document.URL
  End If

End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39486278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档