Thanks
yklooi. That’s good to know. It gives us some tome to incorporate changes to accommodate the new site. I’ll discuss with
polarzbearz to see if we can make this transition as smooth as possible for everyone using the spreadsheet.
-- EDIT --As of 8:30PM, we can no longer get NAV prices from the old link at
https://www.fundsupermart.com.my/main/fundi....tpl?id=MYKNGGF This means that if you're using the old Windows or Mac versions of this spreadsheet, it will no longer retrieve the latest prices since that page is no longer there.
-- EDIT2 --I have a working solution ready for
Windows. If you're feeling adventurous or impatient, below are the steps to modify your own copy of the Excel Spreadsheet to cater for changes in the new FSMOne site. By doing this yourself, you won't have to deal with migrating your existing data into a new updated file. It's pretty straightforward:
MAKE A COPY OF YOUR FILE BEFORE YOU DO THIS! Just in case...
» Click to show Spoiler - click again to hide... «
Instructions
- Right click on the "Update Current Fund Price" button, and choose "Assign Macro"

- Select the macro with the name "GetFundPrices" and click on "Edit"

- Click on the "Tools" menu and choose "References"

- Find the entry that says "Microsoft VBScript Regular Expressions 5.5", put a checkmark on it, and click "OK"

- On the main screen you'll see the subroutine that says "GetFundPrices"

- This subroutine goes all the way down here

- Now select all the lines of code that is in this subroutine. (Select until the line.)

- Press the "Backspace" key or "Delete" key on your keyboard
- Copy the code in the Spoiler section below, and paste it here

Code in here vvvv
» Click to show Spoiler - click again to hide... «
CODE
Sub GetFundPrices()
' ORIGINALLY CREATED BY idyllrain @ Lowyat.net
' ORIGINAL SOURCE(S):
' Â - https://forum.lowyat.net/index.php?showtopic=3633445&view=findpost&p=75357733
' Â - https://forum.lowyat.net/index.php?showtopic=3633445&view=findpost&p=75383114
' UPDATED BY polarzbearz @ Lowyat.net - 16 September 2015
' UPDATED BY idyllrain @ Lowyat.net - 23 December 2015
 Â
' Get current state of various Excel settings
  screenUpdateState = Application.ScreenUpdating
  statusBarState = Application.DisplayStatusBar
  eventsState = Application.EnableEvents
  displayPageBreakState = ActiveSheet.DisplayPageBreaks 'note this is a sheet-level setting
 Â
' Turn off some Excel functionality temporarily to speed up the macro
  Application.ScreenUpdating = False
  Application.DisplayStatusBar = False
  Application.EnableEvents = False
  ActiveSheet.DisplayPageBreaks = False 'note this is a sheet-level setting
 Â
  Set ws = Worksheets("Investment Details")
  Set Connection = CreateObject("winhttp.winhttprequest.5.1") 'Added on v2.1
  'Connection.Option(WinHttpRequestOption_SecureProtocols) = 2048
 Â
  Dim i As Long
  Dim lastRow As Long: lastRow = ws.Range("A:A").Find(What:="0", After:=ws.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
  xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Row
 Â
'Executing logs placeholder
  Dim logs As String
  logs = "Fund update has been successfully executed!" & vbNewLine & "Please refer to the status logs below:" & vbNewLine & vbNewLine
  logs = logs & vbTab & "LINE" & vbTab & "FSM CODE" & vbTab & "STATUS"
 Â
'Set a Number of Updates counter, starting from zero before going into the loop
  Dim successfulUpdate As Long
  Dim totalUpdate As Long
  sucessfulUpdate = 0
  totalUpdate = 0
 Â
' Regular Expression setup (For Windows only)
  Dim regEx As New RegExp
  regEx.Global = False
  regEx.MultiLine = True
  regEx.IgnoreCase = False
  Dim xsrfPattern As String: xsrfPattern = "message.{3}(.{36})"
  Dim priceDatePattern As String: priceDatePattern = "latestNavPrice.+?showDate.:(\d+).+?bidPrice.:([0-9.]+)"
  Dim regmatches As Object
 Â
' Get XSRF Token
  Dim xsrf_token As String: xsrf_token = ""
  Connection.Open "POST", "https://www.fundsupermart.com.my/fsmone/rest/csrf/get-new-csrf-token"
  Connection.Send
  If Connection.Status = 200 Then
    With regEx
      .pattern = xsrfPattern
      If regEx.Test(Connection.ResponseText) Then
        Set regmatches = regEx.Execute(Connection.ResponseText)
      End If
      xsrf_token = regmatches(0).SubMatches(0)
    End With
  End If
 Â
' Process each row that starts with a first cell value of "1"
  For i = 1 To lastRow
    If ws.Cells(i, 1).Value = "1" Then
      totalUpdate = totalUpdate + 1
     Â
      Dim fundName As String
      fundName = ws.Cells(i, 3).Value
     Â
      Connection.Open "POST", "https://www.fundsupermart.com.my/fsmone/rest/fund/get-factsheet?paramSedolnumber=" & fundName, False
      Connection.SetRequestHeader "X-XSRF-TOKEN", xsrf_token
     Â
      On Error GoTo EndHandler: ' terminate if error in connecting
      Connection.Send
      If Connection.Status = 200 Then
        With regEx
          .pattern = priceDatePattern
          If regEx.Test(Connection.ResponseText) Then
            Set regmatches = regEx.Execute(Connection.ResponseText)
            ws.Cells(i, 4).Value = ((regmatches(0).SubMatches(0) + 28800000) / 86400000) + 25569 'Update date value'
            ws.Cells(i, 9).Value = regmatches(0).SubMatches(1) 'Update NAV'
            successfulUpdate = successfulUpdate + 1
            logs = logs & vbNewLine & vbTab & i & vbTab & Left(fundName & Space(15), 15) & vbTab & "OK!"
          Else
            logs = logs & vbNewLine & vbTab & i & vbTab & Left(fundName & Space(15), 15) & vbTab & "ERROR!"
            ws.Cells(i, 4).Value = "=TODAY()"
          End If
        End With
      End If
    End If
  Next i
   Â
' Restore Excel state
  Application.ScreenUpdating = screenUpdateState
  Application.DisplayStatusBar = statusBarState
  Application.EnableEvents = eventsState
  ActiveSheet.DisplayPageBreaks = displayPageBreaksState 'note this is a sheet-level setting
   Â
' Add final line to logs and display to user
  logs = logs & vbNewLine & vbNewLine & "If there are errors in updating the Fund Price, please double check on the FSM Codes and try again."
  MsgBox logs
 WS.Range("portfolioLastUpdate").Value = Date
  Exit Sub
   Â
EndHandler:
  MsgBox ("Unable to connect to FSM website. Please try again later.")
   Â
End Sub
- Finally, go to the "File" menu, "Save" and then choose "Close and Return to Excel"

Attached is an updated base file for Excel 2016 for Windows. Note that this file does not contain functionality that
polarzbearz added when she published her beta version a while ago. This is merely the previous spreadsheet with the FSM retrieval code updated. If you do not want to start afresh, I would recommend following the instructions above to update your own file.
[attachmentid=10144384]
-- EDIT3 --Instructions for
Mac version are available here:
https://forum.lowyat.net/index.php?showtopi...post&p=91308800-- EDIT4 --I updated the instructions and base file above.
Changes- Switched to using a different date value in the API response.
- Fixed timezone issues in date calculation
- Optimized regular expressions
- Removed TLS1.2 connection setting
Thanks to
yklooi for discovering these issues. I should've been more careful. Those who followed my instructions above will have to redo them again. I'm terribly sorry for the trouble; please forgive me.
When I tried download the new spreadsheet and without doing anything, click on the button, same thing happens. Any idea?