Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Object Error 424 when pulling data from Yahoo - what's wrong?

0

I watched the following video and input the same code. For some reason, I'm getting a "run-time error 424 - object required". I can't figure out what's wrong with the code and why it won't return the same value as the video from the Yahoo site

https://www.youtube.com/watch?v=IOzHacoP-u4

Pasted the code below:

Sub Get_Web_Data()

Dim request As Object

Dim response As String

Dim html As New HTMLDocument

Dim price As Variant

'Website to go to.

website = "https://finance.yahoo.com/quote/EURUSD=X/"

' 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 GMT"

' Send the request for the webpage.

request.send

' Get the webpage response data into a variable.

response = StrConv(reuest.responseBody, vbUnicode)

' Put the webpage into an html object to make data references easier.

html.body.innerHTML = response

' Get the price from the specified element on the page.

price = html.getElementsByClassName("Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)")(0).innerText

' Output the price into a message box.

MsgBox price

End Sub

Answer
Discuss

Discussion

Please post your code between code tags so that ti can be easily read and copied. Also state on which line the code breaks with the error you mention. That line indicates the reason for the error. Without that information I can only point you to the lineĀ response = StrConv(reuest.responseBody, vbUnicode) where the variable name "request" is mis-spelled: the curse of omitting Option Explicit at the top of the module.
Variatus (rep: 4889) Aug 23, '20 at 8:41 pm
I'm pretty sure Variatus is right.
don (rep: 1989) Aug 25, '20 at 7:37 am
Add to Discussion



Answer the Question

You must create an account to use the forum. Create an Account or Login