I created a code which is based on a tutorial that i view in this site about importing data from Yahoo site.
The code imports the stock price and the forecast price .
The code import the current stock price but failed to bring the price forecast.
I get the next messege:
run time error "91"
object variable or with block variable not set
I will truly appreciate your help
This is the code:
Sub YAHOO_DATA2()
Dim request As Object
Dim response As String
Dim html As New HTMLDocument
Dim website As String
'Dim price1 As Variant
Dim price2 As Variant
stock = "WFC"
website = "https://finance.yahoo.com/quote/" & stock & "/analysis?p=" & stock
' Create the object that will make the webpage request.
Set request = CreateObject("MSXML2.XMLHTTP")
' Where to go and how to go there - probably don't need to change this.
request.Open "GET", website, False
' Get fresh data.
request.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
' Send the request for the webpage.
request.send
' Get the webpage response data into a variable.
response = StrConv(request.responseBody, vbUnicode)
' Put the webpage into an html object to make data references easier.
html.body.innerHTML = response
' price1- current price, price2- forecast low price
price1 = html.getElementsByClassName("Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)")(0).innerText
' The following command fails!
price2 = html.getElementsByClassName("Pos(r) Fl(start) Fz(xs) C($tertiaryColor)").Item(0).innerText
End Sub