我收到此错误"对象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
答案 0 :(得分:0)
首先确保您已在Internet Explorer上打开网站。然后运行代码。我没有得到你的错误,但有对象引用错误。所以,当对象什么都没有时添加一个检查。
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