运行时错误424需要对象VBA
我试图扫描网页时出现此错误运行时错误424需要对象VBA,vba,excel,Vba,Excel,我试图扫描网页时出现此错误 ' 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.investin
' 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")
以及它的投掷错误
设置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
输出
可能是id“pair_23784”不正确,或者变量allRowOfDataG必须是Stringthat's correct,这是数据的标记that's correct,这是数据的标记that's correct,这是数据的标记
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