CODE
Sub GetFundPrices()
Set WS = Worksheets("Investment Details")
Set htm = CreateObject("htmlFile")
Set XML = CreateObject("msxml2.xmlhttp")
Dim i As Long
Dim lastRow As Long
lastRow = WS.Range("C:C").Find(What:="*exit*", LookIn:=xlValues).Row
'From first row all the way to the row containing the value *exit*'
For i = 1 To lastRow
'If this row is a group header row (Column A has a value of 1)'
If WS.Cells(i, 1).Value = "1" Then
Dim fundName As String
'Get the fund code'
fundName = WS.Cells(i, 3).Value
'Download the correct price list'
XML.Open "GET", "http://www.fundsupermart.com.my/main/fundinfo/dailyPricesHistory.tpl?id=" & fundName, False
XML.send
If XML.ReadyState = 4 And XML.Status = 200 Then
htm.body.innerHTML = XML.responsetext
On Error GoTo ErrHandler:
'Get all 4 cells in the first row of data'
Set FirstRow = htm.getElementsByTagName("tr")(2).Children
'Update date value from 4th table cell of first row'
WS.Cells(i, 4).Value = FirstRow(3).innerText
'Update NAV value from the DIV element in the 3rd table cell of first row'
WS.Cells(i, 9).Value = FirstRow(2).FirstChild().innerText
End If
End If
Next i
Exit Sub
ErrHandler:
MsgBox ("Cannot load data. Either the FSM Code is incorrect or FundSuperMart is down.")
End Sub
Set WS = Worksheets("Investment Details")
Set htm = CreateObject("htmlFile")
Set XML = CreateObject("msxml2.xmlhttp")
Dim i As Long
Dim lastRow As Long
lastRow = WS.Range("C:C").Find(What:="*exit*", LookIn:=xlValues).Row
'From first row all the way to the row containing the value *exit*'
For i = 1 To lastRow
'If this row is a group header row (Column A has a value of 1)'
If WS.Cells(i, 1).Value = "1" Then
Dim fundName As String
'Get the fund code'
fundName = WS.Cells(i, 3).Value
'Download the correct price list'
XML.Open "GET", "http://www.fundsupermart.com.my/main/fundinfo/dailyPricesHistory.tpl?id=" & fundName, False
XML.send
If XML.ReadyState = 4 And XML.Status = 200 Then
htm.body.innerHTML = XML.responsetext
On Error GoTo ErrHandler:
'Get all 4 cells in the first row of data'
Set FirstRow = htm.getElementsByTagName("tr")(2).Children
'Update date value from 4th table cell of first row'
WS.Cells(i, 4).Value = FirstRow(3).innerText
'Update NAV value from the DIV element in the 3rd table cell of first row'
WS.Cells(i, 9).Value = FirstRow(2).FirstChild().innerText
End If
End If
Next i
Exit Sub
ErrHandler:
MsgBox ("Cannot load data. Either the FSM Code is incorrect or FundSuperMart is down.")
End Sub
As this code relies on FSM's price list pages, if there's any changes to that in the future, this code will break. The only modifications done on the table was changing Column C into the Fund Codes used at FundSuperMart (You can get these from the URL: http://www.fundsupermart.com.my/main/fundi...do?sedolnumber=MYKNGGF) and adding the value "*exit*" into the final row of Column C. Like this:

Also, the formula for the Units calculation in Column M will sometimes result in an amount that doesn't reflect the value shown on FSM's website as the rounding order is different.
» Click to show Spoiler - click again to hide... «
QUOTE
Edit 12/7: Testing by polarzbearz reveals that my modification to the rounding formula is still not the formula that FSM uses [ Link to post ]
This post has been edited by idyllrain: Jul 12 2015, 05:45 PM
Jul 12 2015, 12:57 AM
Quote







0.0408sec
0.33
7 queries
GZIP Disabled