如何在VBA中调用bloomberg函数

时间:2014-07-06 07:33:58

标签: excel vba bloomberg

我试图编写vba代码,以便每次输入数字时,它都会成为股票代码之后的" HK Equity"由vba代码添加。然后电子表格可以使用Bloomberg函数BTP返回其RSI。例如,当我输入" 1"在一个单元格中,电子表格将返回股票的RSI" 1 HK Equity"使用Bloomberg函数= BTP($ D3,E $ 2," RSI"," TAPeriod = 14"," DSClose = LAST_PRICE"," Per = d& #34;。)

以下是我的代码:

Sub RSI()
Dim num As Integer
num = Sheets("sheet2").Cells(3, 2).Value

Dim numString As String
numString = CStr(num)

Dim ticker As String
ticker = numString + "HK Equity"

Dim rsiString As String
rsiString = Sheets("sheet2").Cells(4, 2).Value

Sheets("sheet2").Cells(5, 2).Value = "=BTP(" & ticker & "," & rsiString & "," & "RSI" & ", "    & "TAPeriod=14" & "," & "DSClose=LAST_PRICE" & "," & "Per=d" & ")"

End Sub

当我运行代码时,它会显示运行时错误' 1004'应用程序定义或对象定义的错误。并且调试器说最后一个命令有问题(即Sheets(" sheet2")。Cells(5,2).Value =" = BTP ....)什么错误这个命令? THX !!

1 个答案:

答案 0 :(得分:1)

您可以查看BTP公式的输出吗?

' =BTP(1 HK Equity,rsi string,RSI, TAPeriod=14,DSClose=LAST_PRICE,Per=d)
Sheets("sheet2").Cells(5, 2).Value = "=BTP(" & ticker & "," & rsiString & "," & "RSI" & ", "    & "TAPeriod=14" & "," & "DSClose=LAST_PRICE" & "," & "Per=d" & ")"

似乎你错过了所有逃脱角色

"=BTP(""" & ticker  & """,""" & rsiString  & """,""RSI"",""TAPeriod=14"",""DSClose=LAST_PRICE"",""Per=d"")"