A
Andy
According to MS Web site, the old Excel 2002/2003 macro to retrieve stock
quotes is not supported in Excel 2007 (although some, me not included,
supposedly got it to work on their Excel 2007). So I wrote a new one for
Excel 2007 which retrieves from Yahoo (not MSN). Posting here for others in
same situation I was in. To use the macro, select a cell with a stock or
mutual fund symbol and execute the macro GETSTOCK. The resulting stock quote
will be written into cell to the right.
-Andy
Sub GetStock()
Dim s As String
Dim ret As Double
Dim tempSheet As Worksheet
s = Selection.Value
Set tempSheet = ActiveWorkbook.Worksheets.Add
tempSheet.Visible = xlSheetHidden
With tempSheet.QueryTables.Add(Connection:= _
"URL;http://finance.yahoo.com/q/cq?s=" & s,
Destination:=tempSheet.Range("$A$1"))
.Name = "cq?s=msft"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "11"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
ret = tempSheet.Range("C2").Value
Application.DisplayAlerts = False
tempSheet.Delete
Application.DisplayAlerts = True
ActiveCell.Offset(0, 1).Value = ret
End Sub
quotes is not supported in Excel 2007 (although some, me not included,
supposedly got it to work on their Excel 2007). So I wrote a new one for
Excel 2007 which retrieves from Yahoo (not MSN). Posting here for others in
same situation I was in. To use the macro, select a cell with a stock or
mutual fund symbol and execute the macro GETSTOCK. The resulting stock quote
will be written into cell to the right.
-Andy
Sub GetStock()
Dim s As String
Dim ret As Double
Dim tempSheet As Worksheet
s = Selection.Value
Set tempSheet = ActiveWorkbook.Worksheets.Add
tempSheet.Visible = xlSheetHidden
With tempSheet.QueryTables.Add(Connection:= _
"URL;http://finance.yahoo.com/q/cq?s=" & s,
Destination:=tempSheet.Range("$A$1"))
.Name = "cq?s=msft"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "11"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
ret = tempSheet.Range("C2").Value
Application.DisplayAlerts = False
tempSheet.Delete
Application.DisplayAlerts = True
ActiveCell.Offset(0, 1).Value = ret
End Sub