我想知道 VBA 代码中是否有办法强制彭博函数(在电子表格中)更新其值(任何 BDH 函数)
目标开发人员面临类似的问题/拥有彭博终端
我试过什么——
Application.RTD.RefreshData
Application.RTD.throttleInterval = 0
Application.CalculateFull
BDH 函数不会重新加载它们自己。
我现在可以刷新它们的唯一方法是:我单击彭博加载项功能区上的"刷新工作簿"按钮。
由于彭博插件被锁定在 VBE 中,我无法找到必要的代码。我错过了任何彭博参考吗?任何彭博专家/用户都能为我指出正确的方向吗?谢谢。
我通过在记事本中打开关键字"刷新"在 xla 中搜索它。找到以下目标:
RefreshAllWorkbooks
blpmain.xla!RefreshAllStaticData
blpmain.xla!'RefreshWorkbookFundamentalsData
blp.xla!IsBlpRefreshAvailable
我一一试了一下,前 2 个通过调用:
Application.run "RefreshAllWorkbooks"
Application.run "RefreshAllStaticData"
但不是单独调用它们(我想这是因为我可以以某种方式使用 Application.run 调用受保护的公共过程)
RefreshAllWorkbooks
或
RefreshAllStaticData
感谢所有的帮助
我最近从bbg聊天中收到了这个答案。我认为这就是我们都在寻找的...
bbg帮助台:通常我们不会在帮助台上提供有关VBA的帮助,但我找到了以下内容。您可以使用以下 VBA 命令刷新 BDx() 公式:
Refresh based on default option setting: Application.Run "RefreshData"
Refresh current selection: Application.Run "RefreshCurrentSelection"
Refresh current worksheet: Application.Run "RefreshEntireWorksheet"
Refresh current workbook: Application.Run "RefreshEntireWorkbook"
Refresh all workbooks: Application.Run "RefreshAllWorkbooks"
备注:使用VBA宏刷新彭博公式时,当触发刷新的宏正在运行时,公式无法完成请求数据。必须使用 Application.OnTime() 调度第二个函数在触发刷新退出的子例程之后运行。以下代码片段演示了用于刷新所有工作簿的 VBA 代码,后跟调用 processSheet 子例程之前的 10 秒延迟:
Sub refreshSheet()
Application.Run "RefreshEntireWorksheet"
Application.OnTime (Now + TimeValue("00:00:10")), "processSheet"
End Sub
Sub processSheet()
' perform processing here
End Sub
发现更改 BDH 公式中的某些内容会导致刷新。 查找并替换=
符号将进行勾号。
Public Sub Recalc()
Dim ws As Worksheet, FormulaCells As Range, c As Range
Application.Calculation = xlCalculationManual
For Each ws In ThisWorkbook.Worksheets
On Error Resume Next
ws.Activate
Set FormulaCells = ws.UsedRange.SpecialCells(xlCellTypeFormulas).Cells
If Err = 0 Then
For Each c In FormulaCells
c.Formula = Replace(c.Formula, "=", "=")
Next 'c
Else
Err.Clear
End If
Next 'ws
Application.Calculation = xlCalculationAutomatic
End Sub
我从来没有设法做到你的要求。我发现获取最新数据的唯一可靠方法是使用 BLP_DATA_CTRLLib.BlpData
直接从 VBA 调用 API,等待答案,然后将结果放入工作表中。
关于打开受密码保护的VBA代码,谷歌或堆栈溢出搜索应该给你答案。
我有用:
WS.Select
WS.Range("A5").Select 'the cell that contains the BDH function
Application.Run "RefreshCurrentSelection"