问题
I have an Excel sheet with ~300,000 BDH formulas to download securities prices.
I want to
- open the file and get all prices
- paste them as values
- 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:
- I open the file
- the code checks every 30 minutes if all BDH formulas are done
- 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