I came across this post. I tried out the solution suggested by the accepted answer and came up with the following code.
Sub WebScraping()
Dim appIE As Object
Dim myValue As String
Dim iLastRow As Integer
Dim allRowOfData
Application.DisplayAlerts = False
Set appIE = CreateObject("internetexplorer.application")
With appIE
.Navigate "http://uk.investing.com/rates-bonds/financial-futures"
.Visible = False
End With
Do While appIE.Busy
DoEvents
Loop
'Set allRowOfData = appIE.document.getElementById("pair_8907")
Worksheets("Web Scraping").Activate
'myValue = allRowOfData.Cells(7).innerHTML
myValue = appIE.document.getElementById("pair_8907").Cells(7).innerHTML
iLastRow = ActiveSheet.Range("B100000").End(xlUp).Row
ActiveSheet.Cells(iLastRow, 1).Select
If iLastRow = 1 Then
ActiveCell.Offset(1, 0).Value = "US 30Y T-Bond"
ActiveCell.Offset(1, 1).Value = myValue
ActiveCell.Offset(1, 2).Value = Now()
ActiveCell.Offset(1, 2).Select
ElseIf iLastRow > 1 Then
ActiveCell.Copy Destination:=Cells(ActiveCell.Row + 1, 1)
ActiveCell.Offset(1, 1).Value = myValue
ActiveCell.Offset(1, 2).Value = Now()
ActiveCell.Offset(1, 2).Select
End If
appIE.Quit
Set appIE = Nothing
Set allRowOfData = Nothing
End Sub
My script runs smoothly 9 out of 10 times but sometimes it throws an error:
When that happens the VBE debugger shows that the command stops at
myValue = appIE.document.getElementById("pair_8907").Cells(7).innerHTML