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

I would like to use a simple VBA script to call a BDH Bloomberg function at specific locations in my spreadsheet, which is primitively computed.

Although using standard Excel functions does not seem to be a problem, as soon as I insert parts of a Bloomberg function that contain quotation marks (such as "Dates, Period", "H, M"), I get the expected end of a statement error.

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

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

Any help would be greatly appreciated!

Here is the exact code I'm trying to use:

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

      

+3


source to share


2 answers


You need to avoid quotes with a lot of quotation marks. It also doesn't hurt to set a formula property instead of setting a value, but it doesn't need to work for that. These are the quotes that cause a compiler error.



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

      

+1


source


The syntax I found has additional settings at the end that are set like "Setting = x, OtherSetting = y" which will be like my formula below:



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

      

0


source







All Articles