I would like to write into the cell A1 of an Excel sheet the result of the query below, but I don't know what I need to do :
Set myRHistoryManager = CreateHistoryManager
myRHistoryCookie = myRHistoryManager.Initialize("MY BOOK")
Set myRHistoryQuery = myRHistoryManager.CreateHistoryQuery(myRHistoryCookie)
' Set the query parameters accordingly to your needs
With myRHistoryQuery
.InstrumentIdList = "VOWG5YEUAM=R" ' Range("G6").Value
.FieldList = "MID_SPREAD.Timestamp;MID_SPREAD.Close" ' Range("G7").Value 'Or of the form "TRDPRC_1.TIMESTAMP;TRDPRC_1.VALUE;TRDPRC_1.VOLUME"
.RequestParams = "START:" & CDbl(ActiveSheet.Range("A1").Value) & " END:" & CDbl(ActiveSheet.Range("A2").Value) & " INTERVAL:1D" ' Range("G8").Value
.RefreshParams = "FRQ:5S" ' Range("G9").Value
.DisplayParams = "" ' ActiveSheet.Range("G10").Value '"TSREPEAT:YES CH:Fd"
.Subscribe
End With
Exit Sub
Where do I have to write the cell on which I want the result?
Thanks
I have modified the Basic.sample.xlsm to display the result at Cell A1.
Private Sub m_rhistoryQuery_OnImage(ByVal a_historyTable As Variant) ' TODO: Use the data in the array a_historyTable Range(Cells(1, 1), Cells(UBound(a_historyTable, 1), UBound(a_historyTable, 2))).Value = a_historyTable End Sub Private Sub m_rhistoryQuery_OnUpdate(ByVal a_historyTable As Variant, ByVal a_startingRowIndex As Long, ByVal a_startingColumnIndex As Long, ByVal a_shiftDownExistingRows As Boolean) Range(Cells(1, 1), Cells(UBound(a_historyTable, 1), UBound(a_historyTable, 2))).Value = a_historyTable End Sub
Hi,
Is it possible to include this sub into a loop? I would like to query historical data of many assets with VBA to avoid writing RHistory in my Excel sheets for each. When I create a loop, the first lap works, but on the second one, the ".suscribe" functionality doesn't work and no data can be requested.
Do I need to to put something particular?
Thank you.
Hello @benoit.laurent2,
You may find useful RHistory API Examples, Single-Query Sample Excel book conveys output via Cells.
Does this help?
Thank you, but it doesn't help me to understand where I have to give the cell where the answer of the query must be written. By default, in RHistoryAPI.xlsm, there is no place in the code to display the results in termsheet.
Ok thanks. I didn't understand the use of .subsrcibe. I can see this property calls the sub myRHistoryQuery_OnImage when I put a stop on this sub.
Maybe it's not clear enough in the tutorial.
Many thanks for your help.
Best regards.