excel - 等到 Excel 完成使用 VBA 填充 Bloomberg 数据

标签 excel vba bloomberg

我有一个 Excel 表格,其中包含约 300,000 BDH 公式来下载证券价格。

我想要

  • 打开文件并获取所有价格
  • 将它们粘贴为值
  • 保存并关闭文件。

  • 但是,我不知道 Excel 何时完成填充 Bloomberg 数据,因此很难确定执行 2) 和 3) 的时间。

    我写过 VBA,但不确定它是否有效:

    Module1
    Sub CheckFormulas()
    If Application.CalculationState = xlDone Then
        With Worksheets("Sheet1").UsedRange
        .Value = .Value
    End With
    Else
        Application.OnTime Now + TimeValue("00:30:00"), "CheckFormulas"
    
    ActiveWorkbook.Close Savechanges:=True
    End If
    End Sub
    

    在“这本工作簿”中
    Private Sub Run()
    Call CheckFormulas
    End Sub
    

    所以理论上它应该工作的方式是:
  • 我打开文件
  • 如果所有 BDH 公式都完成了,代码每 30 分钟检查一次
  • 如果完成,则粘贴为值,保存并关闭 4) 如果没有,请在 30 分钟后再次检查。

  • 我想知道这是否是实现我的目标的最佳方式,并想知道 Application.CalculationState是否与彭博公式 BDH 兼容或使用?

    最佳答案

    在我们的生产环境中,我们使用一个单元格来检查其公式中是否存在带有“Req”的单元格:

    =SUM(IFERROR(FIND("Req", _range_to_check_with_formulas_ ),0))
    

    在 VBA Sub 中,我们使用 WHILE LOOP 测试单元格值:
    while cell_to_test.value <> 0
        Application.Calculate
        Application.RTD.RefreshData
        DoEvents
    Wend
    
    Call _sub_to_do_some_stuff_
    

    关于excel - 等到 Excel 完成使用 VBA 填充 Bloomberg 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52952324/

    相关文章:

    arrays - 删除数组中的一项

    从命名范围到默认值的 VBA 数据验证

    VBA更改切片器选择当前选定的项目

    excel - VBA 用户窗体 : SpinButtons not working when TextBoxes are formatted using Class Module

    c++ - 通过 API 的彭博股票期权链

    asp.net - 将 GridView 导出到多个 Excel 工作表

    excel - 运行 powershell 命令时出错

    excel - 在 VBA 中使用 Excel Solver 时捕获最大时间/迭代对话框

    python - 通过 Bloomberg 的新数据 API (COM v3) 与 Python 的异步数据?

    python - 彭博 API 的 Pandas 包装器?