Hello!
The goal here is to create a macro that will retrieve mutual fund info. Not the real-time quote but data about the mutual fund. Here is the macro that I recorded. The challenge is in being able to set things up such that the user can input up to 10 ticker symbols and grab, specifically, the Max Front End Sales Fee.
My macro hardcoded the ticker GEGAX.
How can this be set up such that user can load tickers into range A5:A14?
Sub grabMFData()
'
' grabMFData Macro
'
' Keyboard Shortcut: Ctrl+m
'
Range("B16").Select
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://finance.yahoo.com/q/pr?s=gegax+profile", Destination:=Range( _
"$A$1"))
.Name = "pr?s=rymgx+profile"
.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 = "36"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Sheets("Working Version").Select
Range("A16").Select
End Sub
The code below wonderfully extract live quotes. And if the ticker symbol is bogus, this returns "???'" All good.
I've been trying to modify this code to retrieve the Max Fee but it's not going so well.
Sub LoopAllSymbols_RetrieveData()
' Local Variables
Dim rngLookUpSym As Range, rngQuerySym As Range, rngQuerySymCo As Range
Dim rngQuerySymData As Range
Dim qryTableStocks As QueryTable
' Step 1 : Set Data Ranges
Set rngLookUpSym = Worksheets("Stock Symbols").Range("A2")
Set rngQuerySym = Worksheets("Web Query Page").Range("A1")
Set rngQuerySymCo = Worksheets("Web Query Page").Range("A5")
Set rngQuerySymData = Worksheets("Web Query Page").Range("A5").Range("D1:P1")
Set qryTableStocks = ThisWorkbook.Worksheets("Web Query Page").QueryTables(1)
' Step 2 : Loop through list of stocks and retrieve market data
Do While rngLookUpSym <> ""
rngQuerySym = rngLookUpSym
With qryTableStocks
.Connection = _
"URL;http://moneycentral.msn.com/investor/external/excel/quotes.asp?SYMBOL=" & rngQuerySym
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingAll
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
rngLookUpSym.Range("B1") = rngQuerySymCo
rngLookUpSym.Range("D1:P1") = rngQuerySymData.Value
Set rngLookUpSym = rngLookUpSym.Offset(1, 0)
Loop
End Sub
Sub BetterWebQuery()
'
' BetterWebQuery Macro
' Macro recorded 9/30/2004 by Atmel PC
'
'
With ActiveSheet.QueryTables.Add(Connection:= _
"FINDER;C:\Program Files\Microsoft Office\Office\Queries\Microsoft Investor Stock Quotes.iqy" _
, Destination:=Range("A2"))
.Name = "Microsoft Investor Stock Quotes_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingAll
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
Range("A1").Select
ActiveCell.FormulaR1C1 = "Atml"
Range("A1").Select
End Sub
Bookmarks