Wait until Excel finishes populating Bloomberg data using VBA

风格不统一 提交于 2021-02-07 20:29:15

问题


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

I want to

  1. open the file and get all prices
  2. paste them as values
  3. save and close the file.

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

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

In 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

In 'ThisWorkbook'

Private Sub Run()
Call CheckFormulas
End Sub

So the way it should theoretically work is:

  1. I open the file
  2. the code checks every 30 minutes if all BDH formulas are done
  3. if they are done, then paste as values, save and close 4) if not, check 30 minutes later again.

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?


回答1:


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))

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_


来源:https://stackoverflow.com/questions/52952324/wait-until-excel-finishes-populating-bloomberg-data-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!