How to use Bloomberg Data History (BDH) command within Microsoft Visual Basic (VBA for Excel)

匆匆过客 提交于 2019-12-07 17:31:28

问题


I would like to use a simple VBA script to call the Bloomberg BDH function in specific locations of my spreadsheet, which is computationally primitive.

While the use of standard Excel functions doesn't see to be a problem, as soon as I insert the parts of the Bloomberg function that contain quotation marks (such as "Dates,Period", "H,M") I get an expected end of statement error.

All I want to do is insert these function calls into specified cells. Unfortunately I have no experience with VBA and don't know why the quotation marks seem to mess it up.

Is there an alternative for the =BDH function which doesn't use symbols that VBA doesn't like? Or is there any other way to insert a Bloomberg function into a specified cell using a marco?

Any help would be greatly appreciated!

Here's the exact code I am trying to use:

Range("B16").Value = "=BDH("TSLA", "PX_LAST", "01/01/2014", "01/03/2014", "Period, Dates", "M,H")"

回答1:


You have to escape the quotes with more quotes. It also doesn't hurt to set the formula property instead of setting the value, but it isn't necessary for this to work. It's the quotes that are causing the compiler error.

Range("B16").Formula = "=BDH(""TSLA"", ""PX_LAST"", ""01/01/2014"", ""01/03/2014"", ""Period, Dates"", ""M,H"")"



回答2:


The syntax I found has the optional settings at the end being set as "Setting=x, OtherSetting=y" which would be how my formula below is set up:

Range("B16").Formula = "=BDH(""TSLA"", ""PX_LAST"", ""01/01/2014"", ""01/03/2014"", ""Period=M, Dates=H"")"


来源:https://stackoverflow.com/questions/27236721/how-to-use-bloomberg-data-history-bdh-command-within-microsoft-visual-basic-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!