等待直到Excel完成使用VBA填充B​​loomberg数据 [英] Wait until Excel finishes populating Bloomberg data using VBA

查看:72
本文介绍了等待直到Excel完成使用VBA填充B​​loomberg数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含300,000 BDH公式的Excel工作表,用于下载证券价格.

I have an Excel sheet with ~300,000 BDH formulas to download securities prices.

我想

  1. 打开文件并获取所有价格
  2. 将它们粘贴为值
  3. 保存并关闭文件.

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

However, I do not know when Excel finishes populating Bloomberg data, so it's difficult to determine the time to do 2) and 3).

我已经写了VBA,但不确定是否可以工作:

I have written VBA, but not sure if it works:

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

因此,它在理论上应该起作用的方式是:

So the way it should theoretically work is:

  1. 我打开文件
  2. 代码每30分钟检查一次BDH公式是否全部完成
  3. 如果完成,然后粘贴为值,保存并关闭4)如果没有,请在30分钟后再次检查.

我想知道这是否是实现我的目标的最佳方法,并且想知道 Application.CalculationState 是否兼容或与Bloomberg公式BDH兼容?

I am wondering if this is the best way to accomplish my goal and want to know if Application.CalculationState is compatible or works with Bloomberg formulas BDH?

推荐答案

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

In our production environment we use a cell that checks if there are cells with "Req" in their formula:

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

在VBA Sub中,我们使用WHILE LOOP测试单元格值:

In a VBA Sub, we test the cell value with a WHILE LOOP:

while cell_to_test.value <> 0
    Application.Calculate
    Application.RTD.RefreshData
    DoEvents
Wend

Call _sub_to_do_some_stuff_

这篇关于等待直到Excel完成使用VBA填充B​​loomberg数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆