For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 0 0 0

How to show results of a RHistory query with VBA into an Excel sheet?

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


eikoneikon-data-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikonpythoneikon-com-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvote
Accepted
38.1k 71 35 53

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

Basic.sample.zip


basicsample.zip (26.1 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

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.

Upvotes
23k 22 9 14

Hello @benoit.laurent2,

You may find useful RHistory API Examples, Single-Query Sample Excel book conveys output via Cells.

Does this help?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
1 0 0 0

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.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
1 0 0 0

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.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea