Internet Explorer 运行时错误 462

use*_*196 4 excel vba

我正在尝试使用 VBA 从 Excel 访问网页。我可以启动 Internet Explorer,并且看到网页出现,但当我点击 Do Until internet.ReadyState >= 4 行代码时,出现运行时错误 462。有任何想法吗?最终我希望能够解析一个网站并获取该网站上的链接列表并选择一个,然后“单击”该链接。建议和帮助会很好。这是我正在使用的函数(我在网上找到的):

Public Sub clicklick()

Dim internet As Object
Dim internetdata As Object
Dim div_result As Object
Dim header_links As Object
Dim link As Object
Dim URL As String

Set internet = CreateObject("InternetExplorer.Application")
internet.Visible = True

URL = "https://www.google.co.in/search?q=how+to+program+in+vba"
internet.Navigate URL


Do Until internet.ReadyState >= 4
    DoEvents
Loop

Application.Wait Now + TimeSerial(0, 0, 5)

Set internetdata = internet.Document
Set div_result = internetdata.getelementbyid("res")


Set header_links = div_result.getelementsbytagname("h3")

For Each h In header_links
    Set link = h.ChildNodes.Item(0)
    Cells(Range("A" & Rows.count).End(xlUp).row + 1, 1) = link.href
Next

MsgBox "done"

End Sub
Run Code Online (Sandbox Code Playgroud)

谢谢你,艾伦

Sac*_*chu 5

我在 VBA 中遇到了类似的错误,并且使用 Set objIE = New InternetExplorerMediumSet objIE = CreateObject("InternetExplorer.Application")不是解决了问题。我通过转到 IE 设置 -> Internet 选项 -> 安全并取消选中“启用保护模式”选项解决了该问题设置