gpt4 book ai didi

excel - 在 Excel VBA 宏完成之前不会填充 Bloomberg 数据

转载 作者:行者123 更新时间:2023-12-01 18:56:32 26 4
gpt4 key购买 nike

我正在具有 Bloomberg 许可证的 PC 上的空白 Excel 2007 工作簿中运行宏。该宏将 Bloomberg 函数插入到 Sheet1 中,以提取 yield 曲线数据。一些附加函数的结果取决于第一个函数完成并正确显示 Bberg 数据。当我单步执行该程序时,它仅显示“#N/A Requesting Data”。 。 .'而不是查询的结果,无论我走得多慢。由于某些函数依赖于填充的字符串和数字字段结果,因此程序会在该代码处遇到运行时错误。当我停止调试时——完全结束程序的运行——所有应该填充的 Bberg 值都会出现。我希望这些值在程序仍在运行时出现。

我尝试使用 DoEvents 和 Application.OnTime() 的组合将控制权返回给操作系统并使程序等待很长时间才能更新数据,但都不起作用。任何想法都会有帮助。我的代码如下。 wb 是全局级工作簿,ws1 是全局级工作表。

Public Sub Run_Me()

'Application.DisplayAlerts = False
'Application.ScreenUpdating = False

Call Populate_Me
Call Format_Me

'Application.DisplayAlerts = True
'Application.ScreenUpdating = True

End Sub
Private Sub Populate_Me()

Dim lRow_PM As Integer
Dim xlCalc As XlCalculation

Set wb = ThisWorkbook
Set ws1 = wb.Sheets(1)

'clear out any values from previous day
If wb.Sheets(ws1.Name).Range("A1").Value <> "" Then
wb.Sheets(ws1.Name).Select
Selection.ClearContents
End If


xlCalc = Application.Calculation
Application.Calculation = xlCalculationAutomatic

Range("A1").Value = "F5"
Range("B1").Value = "Term"
Range("C1").Value = "PX LAST"

Range("A2").Select
ActiveCell.FormulaR1C1 = "=BDS(""YCCF0005 Index"",""CURVE_MEMBERS"",""cols=1;rows=15"")"
BloombergUI.RefreshAllStaticData

Range("B2").Select
ActiveCell.FormulaR1C1 = "=BDS(""YCCF0005 Index"",""CURVE_TERMS"",""cols=1;rows=15"")"
BloombergUI.RefreshAllStaticData

Application.OnTime Now + TimeValue("00:00:10"), "HardCode"

'******more code*******'
End Sub
Sub HardCode()

Range("C2").Select
ActiveCell.FormulaR1C1 = "=BDP($A2,C$1)"
BloombergUI.RefreshAllStaticData

End Sub

最佳答案

解决此问题的一种方法是,在将 Bloomberg 数据拉入不同的子程序后,将您想要运行的所有子程序等放入其中。每次调用 Bloomberg 信息时都必须执行此操作。如果您在 Application.OnTime Now +TimeValue("00:00:15") 之后调用“主”子中的另一个子,它将失败 - 您必须将以下所有子都放入新的主子中。

例如:而不是

Sub Master1()
Application.Run "RefreshAllStaticData"
Application.OnTime Now + TimeValue("00:00:15"), "OtherSub1"
'This will cause the Bloomberg Data to not refresh until OtherSub2 and 3 have run
OtherSub2
OtherSub3
End Sub

应该是

Sub Master1()
Application.Run "RefreshAllStaticData"
Application.OnTime Now + TimeValue("00:00:15"), "Master2"
End Sub

Sub Master2()
OtherSub1
OtherSub2
OtherSub3
End Sub

希望有帮助

关于excel - 在 Excel VBA 宏完成之前不会填充 Bloomberg 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8669845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com