Share via

Getting stock quotes into my spreadsheet

Anonymous
2018-10-18T13:05:19+00:00

I have a spreadsheet with stock symbols in column a and would like to automatically get the current prices in column b. I do have the stock connector task pane, and tried recording a macro that would copy the symbols from column a1 and paste into the box in the task pane, then return the result into b1.  All it did was the copy.  

If using the task pane isn't going to work, perhaps a macro that would reference yahoo.finance perhaps.

I did find a macro from the web, but I'm having a problem with it.  It probably just needs a minor tweak, but I'm not a macro expert.  Here it is, if you'd like to take a look....

Sub Macro1()

'

' Macro1 Macro

'

'

Dim W As Worksheet: Set W = ActiveSheet

Dim last As Integer: last = W.Range("A1000").End(xlUp).Row

If last = 1 Then Exit Sub

Dim symbols As String

Dim i As Integer

For i = 2 To last

 symbols = symbols & W.Range("A" & i).Value & "+"

Next i

 symbols = Left(symbols, Len(symbols) - 1)

Dim Url As String: Url = "http://finance.yahoo.com/d/quotes.csv?s=" & symbols & "&f=snl1hg"

Dim Http As New WinHttpRequest

Http.Open "Get", Url, False

Http.Send

Dim Resp As String: Resp = Http.ResponseText

Dim Lines As Variant: Lines = Split(Resp, vbNewLine)

Dim sLine As String

Dim Values As Variant

For i = 0 To UBound(Lines)   

  sLine = Lines(i)

  If InStr(sLine, ",") > 0 Then

    Values = Split(sLine, ",")

    W.Cells(i + 2, 2).Value = Split(Split(sLine, Chr(34) & "," & Chr(34))(1), Chr(34))(0)

    W.Cells(i + 2, 3).Value = Values(UBound(Values) - 2)

    W.Cells(i + 2, 4).Value = Values(UBound(Values) - 1)

    W.Cells(i + 2, 5).Value = Values(UBound(Values))

  End If

Next i

W.Cells.Columns.AutoFit

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

10 answers

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2018-10-18T17:01:42+00:00

    I can understand your perseverance, but my answer remains the same:

    No way, this is no longer possible.

    Andreas.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2018-10-18T16:48:19+00:00

    Thanks Andreas for the explanation for API.   As that article mentions, the STOCK data type was still in beta at least as of last June.  I do not have it in my version of Excel.  Perhaps I could download an update to my office that would have it?

    Again, I do have that stock connector task pane.  Wouldn't there be a way to code a macro that would loop thru my column of symbols, sending each symbol to the text box there?

    Was this answer helpful?

    0 comments No comments
  3. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2018-10-18T16:13:20+00:00

    API is the abbreviation for Application Programming Interface. Generalized, this means getting an interface to access a program (or website or database or similar things).

    Yahoo has disabled the access for programs to get this data automatically.

    Did you tried the way mentioned in this article?

    https://support.office.com/en-us/article/get-a-...

    Andreas.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2018-10-18T15:17:49+00:00

    Ok, thanks. Not really sure what an API is.  I'm ABSOLUTELY certain my bank isn't going to be helping me write any excel macros! :)

     However,  if you go to finance.yahoo.com, the first thing you see is a box where you can type in a stock symbol, and it brings up the quote.  Can I not make use of that?

    If not, then how about the excel built in stock connector task pane.  Isn't there a way to automate the process, via macro I would assume, of getting the stock symbol into that box and then going thru a loop for all values in the column?

    Was this answer helpful?

    0 comments No comments
  5. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2018-10-18T13:45:10+00:00

    I'm sorry, I only have bad news:

    This feature from Yahoo was discontinued by the Finance team and they will not be reintroducing that functionality.

    AFAIK there is no official free API available that can work as replacement. You have to call your bank and ask for support.

    Andreas.

    Was this answer helpful?

    0 comments No comments