我想使用VBA從excel訪問網頁。我可以啓動Internet Explorer,並且看到網頁出現,但是當我點擊「直到internet.ReadyState> = 4行代碼」時,出現運行時錯誤462。有任何想法嗎?最終我希望能夠解析網站並獲取該網站上的鏈接列表並選擇一個,然後在該鏈接上單擊「單擊」。建議和幫助會很好。這裏是函數(即我在網上找到),我現在用:與Internet Explorer的運行時錯誤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
謝謝你, 艾倫
該代碼似乎沒關係,並獲得鏈接。什麼錯誤來到你的電腦。把錯誤截圖也是如此。 – harun24hr