Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Macro to retrieve stock quotes in Excel 2007

So, for each quote you have to select a cell with the symbolfire the macro which creates a sheetcreates an external querycopies the cell(testing in showed cell d2 instead of cell c2)delete the temp sheet. At least you could loop it for each symbol in a list

You may like mine better which uses a yahoo web fetch to get all at once with ONE mouse click. If you want the file ask OFF list. I will NOT respond to requests made here as that is rude to the other users.
Updated 07/09/08 10:18 AM $ 200.00
$ 15,550.00 $ 15,350.00
Symbol Name Basis Shares Last Trade Value Profit
IBM INTL BUSINESS MAC $ 100.00 100.00 $ 122.39 $ 12,239.00 $ 12,139.00
T AT&T INC. $ 100.00 100.00 $ 33.11 $ 3,311.00 $ 3,211.00
MSFT MICROSOFT CP - $ 25.65 $ -
FE FIRSTENERGY CP - $ 82.73 $ -

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Andy" wrote in message ...
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

Reply
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 09:13 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"