VBA to refresh Bloomberg data not running in proper order

后端 未结 3 1488
[愿得一人]
[愿得一人] 2020-12-06 03:34

my purpose is to update Bloomberg data and do some calculatations with different tickers. But it seems that VBA will run all the calculations without waiting the data to be

3条回答
  •  温柔的废话
    2020-12-06 04:28

    You have to split it up between a check and a refresh.

    Sub RefreshData()
    
    Application.Calculation = xlCalculationAutomatic
    
    Worksheets("Sheet1").Range("A1:A4").Select 'the cells "data1" contains the function =BDH(ticker, field, start date, end date) to get the information from Bloomberg'
    
    Application.Run "RefreshCurrentSelection"
    
    'Check to see if it filled
    Call Check_API
    
    End Sub
    
    Sub Check_API()
    
    If Application.WorksheetFunction.CountIfs(Range("A1:A4"), "#N/A Requesting Data...") > 0 Then
        'Check every 3 seconds
         Application.OnTime Now + TimeValue("00:00:03"), "Check_API"
    Else
    
        'What to do after API filled
         Worksheets("sheet1").Range("D3").Value = Application.WorksheetFunction.Sum(Worksheets("Sheet1").Range("A1:A4")) 'the cells "sum" takes the sum of all BB info'
    End If
    
    End Sub
    

    Also, instead of focusing on the selection, you can do:

    Refresh based on default option setting:

          Application.Run "RefreshData"
    

    Refresh current selection:

          Application.Run "RefreshCurrentSelection"
    

    Refresh current worksheet:

          Application.Run "RefreshEntireWorksheet"
    

    Refresh current workbook:

          Application.Run "RefreshEntireWorkbook"
    

    Refresh all workbooks:

          Application.Run "RefreshAllWorkbooks"
    

    If you were interested. Still the better option is implementing the v3 COM API class that can be found in Bloomberg's SDK with VBA examples.

提交回复
热议问题