[英]method document of object iwebbrowser2 failed
I am getting this error "method document of object iwebbrowser2 failed".. Please look the code below. 我收到此错误“对象iwebbrowser2的方法文档失败”。。请查看下面的代码。
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
First make sure you have opened a site on Internet Explorer. 首先,请确保您已经在Internet Explorer上打开了一个站点。 Then run the code.
然后运行代码。 I did not get the error as yours but got object reference error.
我没有得到您的错误,但是得到了对象引用错误。 So, added a check when the object is nothing.
因此,在对象为空时添加了检查。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.