如何在 Microsoft Visual Basic (VBA for Excel) 中使用 Bloomberg Data History (BDH) 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27236721/
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
How to use Bloomberg Data History (BDH) command within Microsoft Visual Basic (VBA for Excel)
提问by Constantin
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.
我想使用一个简单的 VBA 脚本在我的电子表格的特定位置调用 Bloomberg BDH 函数,这在计算上是原始的。
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 statementerror.
虽然使用标准 Excel 函数似乎没有问题,但只要我插入包含引号的 Bloomberg 函数部分(例如“日期、期间”、“H、M”),我就会得到预期的结果语句结束错误。
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.
我想要做的就是将这些函数调用插入到指定的单元格中。不幸的是,我没有使用 VBA 的经验,也不知道为什么引号似乎把它搞砸了。
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?
是否有不使用 VBA 不喜欢的符号的 =BDH 函数的替代方法?或者有没有其他方法可以使用 marco 将 Bloomberg 函数插入到指定的单元格中?
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")"
采纳答案by RubberDuck
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"")"
回答by Chrismas007
The syntax I foundhas the optional settings at the end being set as "Setting=x, OtherSetting=y" which would be how my formula below is set up:
我发现的语法在末尾有可选设置被设置为“Setting=x,OtherSetting=y”,这就是我下面的公式的设置方式:
Range("B16").Formula = "=BDH(""TSLA"", ""PX_LAST"", ""01/01/2014"", ""01/03/2014"", ""Period=M, Dates=H"")"