User-defined type not defined

jirakst

New Member
Joined
May 9, 2015
Messages
7
I am have here a code to retrieve an actual price of a stock from Google Finance.
Code:
<code>Function StockQuote(ByVal Stock)

Dim URL As String
Dim http As New MSXML2.XMLHTTP
Dim stockdoc As New HTMLDocument

URL = "https://www.google.com/finance?q=" & Stock

http.Open "GET", URL, False
http.Send
stockdoc.body.innerHTML = http.ResponseText
StockQuote = stockdoc.getElementsByClassName("pr")(0).innerText
Set http = Nothing

End Function</code>
Unfortunetlly when I try to make it run it appears a "Compile error: User-defined type not defined." on the second line of the code "Dim http As New MSXML2.XMLHTTP"
I believe I've omited include some refrences.
Here's what I've additionaly mark off in Tools-References:
  • Microsoft XML, v6
  • Microsoft HTML Object Library
Does somebody know what I've done worng?
Thank you in advance.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi jirakst,

I think you are missing this reference: Microsoft WinHTTP Services, version 5.1

Additionally, do yourself a favor and watch this video. It explains how to write a great VBA code to get stock prices with the Yahoo Finance API, which is what you using in your code above. I (and a ton of other people) use this program as a base for my own financial spreadsheet. It's great. You will definitely learn something.

https://www.youtube.com/watch?v=iSlBE3CWg5Q

If you any questions after, feel free.

igold
 
Upvote 0

Forum statistics

Threads
1,222,902
Messages
6,168,938
Members
452,227
Latest member
sam1121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top