vba 路透社检索到数据后继续
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23362256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Continue after reuters has retrieved data
提问by user3417414
Thomson Reuters Eikon used:
汤森路透 Eikon 使用过:
I need to get data from reuters regarding fx spot prices. This is easily done with a reuters formula. However, I need to use this data in a VBA script. Part of the VBA script inserts the formula, reuters then retrieves data but this can take a while (10-20 seconds).
我需要从路透社获取有关外汇现货价格的数据。这很容易用路透社的公式完成。但是,我需要在 VBA 脚本中使用这些数据。VBA 脚本的一部分插入公式,然后路透社检索数据,但这可能需要一段时间(10-20 秒)。
How do i make the VBA script pause until reuters has retrieved the data? (in the first 10 seconds the cell of the reuters data says: 'retrieving....'
如何让 VBA 脚本暂停,直到路透社检索到数据?(在前 10 秒内,路透社数据的单元格显示:“正在检索......”
Range("B2").value = Application.Evaluate("RtGet(" & IDN & "," & RWAL & "," & MIDPRICE & "," & TYPENUM & ")")
This code is now used to insert the formula where RWAL is the exchange rate identifier (such as EUR=)
此代码现在用于插入公式,其中 RWAL 是汇率标识符(例如 EUR=)
回答by Neil Shah
We need to use application.run to use the RtGet function in code as its really a worksheet function. Because its a worksheet function, the data will not be retrieved while code is running.
我们需要使用 application.run 在代码中使用 RtGet 函数,因为它实际上是一个工作表函数。因为它是一个工作表函数,所以在代码运行时不会检索数据。
To get round this we use Application.RTD.RefreshData to pull the data from the RTD server
为了解决这个问题,我们使用 Application.RTD.RefreshData 从 RTD 服务器中提取数据
Function getField(ric As String, field As String) As String
Data = Application.Run("RtGet", "IDN", ric, field)
Do While VBA.Left(CStr(Data), 3) = "Ret" 'ie loop while it is retrieving data
Application.RTD.RefreshData
DoEvents
Data = Application.Run("RtGet", "IDN", ric, field)
Debug.Print Data
Loop
getField = Data
End Function
Public Sub testGetField()
Dim test
test = getField("EUR=", "BID")
End Sub