簡體   English   中英

運行時錯誤424對象需要VBA

[英]run time error 424 object required VBA

我通過嘗試掃描網頁而收到此錯誤

' need to browse the web, I need a browser! So I create an Internet Explorer browser
Dim appIE As Object
Set appIE = CreateObject("internetexplorer.application")
Dim allRowOfDataG As Object

With appIE
    .Navigate "https://uk.investing.com/rates-bonds/portugal-government-bonds?maturity_from=70&maturity_to=260"
    .Visible = False
End With

Do While appIE.Busy
    DoEvents
Loop

'2y
Set allRowOfDataG = appIE.document.getElementById("pair_23784")

及其在Set allRowOfDataG = appIE.document.getElementById(“ pair_23784”)上引發的錯誤

我可以從下面提取一些數據。 也許您應該使appIE可見以進行故障排除。

Option Explicit

Sub SO41622944()
    On Error Resume Next
    ' need to browse the web, I need a browser! So I create an Internet Explorer browser
    Dim appIE As Object
    Dim allRowOfDataG As Object, i As Long, sText As String

    Set appIE = CreateObject("internetexplorer.application")
    If appIE Is Nothing Then Exit Sub
    With appIE
        .Navigate "https://uk.investing.com/rates-bonds/portugal-government-bonds?maturity_from=70&maturity_to=260"
        .Visible = False
        Do While .Busy
            DoEvents
        Loop
        '2y
        Set allRowOfDataG = .document.getElementById("pair_23784")
        If Not allRowOfDataG Is Nothing Then
            Debug.Print "Total items in allRowOfDataG: " & allRowOfDataG.all.Length
            For i = 0 To allRowOfDataG.all.Length - 1
                sText = Trim(allRowOfDataG.all(i).outerText)
                If Len(sText) > 0 Then Debug.Print i, sText ' Skip blank cells
            Next
            Set allRowOfDataG = Nothing
        End If
        .Quit
    End With
    Set appIE = Nothing
End Sub

產量

Total items in allRowOfDataG: 14
 2            Portugal 2-Year
 3            Portugal 2-Year
 5            0.258
 6            0.261
 7            0.311
 8            0.226
 9            -0.003
 10           -1.15%
 11           18:00:01

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM