Excel VBA Script that Downloads Historical Stock Data from Yahoo Finance and Imports it into a Spreadsheet

Before running this script, you must first install DownloadGT
Option Explicit
REM We use "Option Explicit" to help us check for coding mistakes' 
REM Run Excel, then Press Alt+F11 to open VBA
REM Programming by Greg Thatcher, http://www.GregThatcher.com

Function DownloadStockQuotesFromYahoo()
    Dim oCOMAddin
    Dim oComAddinObject
    
    Set oCOMAddin = Application.COMAddIns.Item("DownloadGT.Connect")
    If Err.Number <> 0 Then
        MsgBox "There was an error retrieving a reference to DownloadGT!  Make sure it is installed!"
        Exit Function
    End If
    'Check to see whether the COM add-in is connected
    If oCOMAddin.Connect = False Then
        MsgBox _
            "DownloadGT must be enabled inside Excel before you can call its methods!"
        Exit Function
    End If
   
    Set oComAddinObject = Application.COMAddIns.Item("DownloadGT.Connect").Object
    
    REM Download Microsoft Stock Quotes
    oComAddinObject.DownloadYahooFinanceStockData("MSFT")
    REM Download Google Stock Quotes
    oComAddinObject.DownloadYahooFinanceStockData("GOOG")
    REM Download Netflix Stock Quotes
    oComAddinObject.DownloadYahooFinanceStockData("NFLX")
   
End Function

Problems, Comments, Suggestions? Click here to contact Greg Thatcher

Please read my Disclaimer





Copyright (c) 2013 Thatcher Development Software, LLC. All rights reserved. No claim to original U.S. Gov't works.