Refresh RHistory when workbook open via API

Dears,


I would like to launch query when workbook open and save as new excel file after all value update.

However, it can't refresh all values before auto save as a new excel file

Here is my VBA code (modify RHistoryAPI.xlsm)

Private Sub Workbook_Open()
Dim MyWS As Worksheet
Dim l_historyManager As HistoryManager
Dim l_historyQuery As HistoryQuery
Dim l_destinationRange As Range
Dim l_result As String
Set MyWS = Worksheets("Reuters")
Set l_historyManager = RHistoryVBA.GetHistoryManager
Set l_historyQuery = l_historyManager.CreateQuery("$D$6")
Set l_destinationRange = MyWS.Range("D6").Offset(2, 0)
....
...Subscribe Setting.....
....
l_result = l_historyQuery.Subscribe(a_instrumentIdList, a_fieldList, _
a_requestParams, a_refreshParams, a_displayParams, l_destinationRange, 2)
MyWS.Range("D6").Value = l_destinationRange.Address
....
...SaveAs Coding....
...
Thisworkbook.Save
Thisworkbook.Close
End Sub

Best Answer

  • Zhenya Kovalyov
    Answer ✓

    I would advise to fully utilize the event model of the RHistoryQuery object and save the sheet on the OnUpdate() event. This way it would be easier to troubleshoot the issue that you are having with Excel.