LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Macro to retrieve stock quotes in Excel 2007

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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MSN Stock Quotes Addin for Excel 2007 Martygeo Excel Discussion (Misc queries) 1 June 5th 07 11:33 PM
How to edit MSN Stock Quotes in Excel 2007 TDR[_2_] Excel Discussion (Misc queries) 4 May 15th 07 05:39 PM
Get stock quotes in Excel 2007 Chris Excel Discussion (Misc queries) 4 May 4th 07 04:49 AM
Stock Quotes for Excel 2007 Don Excel Discussion (Misc queries) 0 February 9th 07 02:18 PM
MSN Stock Quotes in Excel 2007 Beta Trader_in_Paradise Excel Discussion (Misc queries) 0 June 7th 06 09:44 PM


All times are GMT +1. The time now is 02:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"