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

Constantin picture Constantin · Dec 1, 2014 · Viewed 9.4k times · Source

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")"

Answer

RubberDuck picture RubberDuck · Dec 1, 2014

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"")"