此代码段应该可以工作,但是我尚未在当前计算机上对其进行过测试:如果出现任何错误,请探索对代码,字段和日期使用或删除数组. Dim arrData作为变体将objDataX变暗为BLP_DATA_CTRLLib.BlpData 将objDataX设置为BLP_DATA_CTRLLib.BlpData arrData = objDataX.BLPGetHistoricalData(Array(ticker),"PX_LAST",start_date,end_date) 您需要检查返回的数组:您并非总是从彭博社那里获得简单的2D网格",有时它是嵌套数组的结构.I am trying to import Bloomberg historical data directly into an array in VBA:Dim data As Variantticker = "UKGRABIQ Index"start_date = "12/31/1998"end_date = "3/31/2015"data = Application.WorksheetFunction.BDH(ticker, "PX_LAST", start_date, end_date, "ARRAY=TRUE")Range("A1", "A66").Value = dataThe end goal is to be able to do a lot of manipulation on that data, not to just have it appear in the worksheet.Thanks in advance for the help. 解决方案 The BDH() function is provided by the Bloomberg Add-ins: it isn't a native Excel Worksheet function, so the Application.WorksheetFunction collection won't have it. You can still use BDH that way, more or less: the Application.Evaluate() method does what you're trying to do with Application.WorksheetFunction. Here's the documentation: https://msdn.microsoft.com/en-us/library/office/ff193019.aspxHowever, I would recommend that you explore the ActiveX objects available to VBA, rather than attempting to emulate a worksheet calculation in VBA code.You'll need to go to the VBA IDE menu, Tools > References... and browse for the Bloomberg Active-X data control, which is usually in C:\blp\API\ActiveX\blpdatax.dllThis code snippet should work, but I haven't tested it on my current machine: explore the use (or removal) of arrays for the tickers, fields and dates if you get any errors.Dim arrData As VariantDim objDataX As BLP_DATA_CTRLLib.BlpDataSet objDataX As BLP_DATA_CTRLLib.BlpDataarrData = objDataX.BLPGetHistoricalData( Array(ticker), "PX_LAST", start_date, end_date )You'll need to inspect the returned array: you don't always get a simple 2D 'grid' from Bloomberg, it's sometimes a structure of nested arrays. 这篇关于彭博数据...为什么Application.WorksheetFunction.BDH不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-19 06:28