Hello, this code was working fine but some months ago stopped working.
It used to get me the stock price from yahoo finance.
- The problem is located in the last line of the macro code, which is the following line:
c.Offset(0, 1).Value = html.getElementsByClassName("Fw(b) Fz(36px) Mb(-4px) D(ib)").Item(0).innerText
- Then I changed it for this one (which extract the price, but it comes along with other data I dont need):
c.Offset(0, 1).Value = html.getElementsByClassName("D(ib) Mend(20px)").Item(0).innerText
I'll be very thanksfull if someone knows how to fix it.
THE FULL ORIGINAL CODE IS THE FOLLOWING:
Sub Get_Web_Data()
Dim response As String
Dim html As New HTMLDocument
Dim website As String
Dim price As Variant
Set tickerrange = Range("D2:D24")
For Each c In tickerrange
If c.Value = "" Then
c.Offset(0, 1).Value = ""
Else
website = "https://finance.yahoo.com/quote/" & c.Value & ".L"
Set request = CreateObject("MSXML2.XMLHTTP")
request.Open "GET", website, False
request.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
request.send
response = StrConv(request.responseBody, vbUnicode)
html.body.innerHTML = response
c.Offset(0, 1).Value = html.getElementsByClassName("Fw(b) Fz(36px) Mb(-4px) D(ib)").Item(0).innerText
End If
Next c
End Sub