我收到这个错误"method document of object iwebbrowser2 failed“。请看下面的代码。
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发布于 2016-09-14 17:42:53
首先,确保您已在Internet Explorer上打开了一个站点。然后运行代码。我没有得到和你一样的错误,但是得到了对象引用错误。因此,在对象为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 Subhttps://stackoverflow.com/questions/39486278
复制相似问题