How to refresh/load RTD Bloomberg function (BDH) in excel in vba

前端 未结 4 1016
梦如初夏
梦如初夏 2020-12-09 06:25

I would like to know if there\'s a way in VBA code forcing the bloomberg functions (In spreadsheet) to update its value( Any BDH functions)

Targeting Develo

相关标签:
4条回答
  • 2020-12-09 07:00

    This works for me:

    WS.Select
    WS.Range("A5").Select 'the cell that contains the BDH function
    Application.Run "RefreshCurrentSelection"
    
    0 讨论(0)
  • 2020-12-09 07:16

    I did a searching of the keyword "refresh" in the xla by opening it in notepad. Found the following targets:

    RefreshAllWorkbooks
    blpmain.xla!RefreshAllStaticData
    blpmain.xla!'RefreshWorkbookFundamentalsData
    blp.xla!IsBlpRefreshAvailable
    

    I tried them out one by one, the first 2 works by calling:

    Application.run "RefreshAllWorkbooks"
    Application.run "RefreshAllStaticData"
    

    But not calling them alone ( I guess it's because I somehow can call protected PUBLIC procedure using Application.run)

    RefreshAllWorkbooks
    

    or

    RefreshAllStaticData
    

    Thanks for all the help

    0 讨论(0)
  • 2020-12-09 07:19

    I have never managed to do what you ask for. The only reliable way I have found to get up-to-date data is by calling the API directly from VBA with BLP_DATA_CTRLLib.BlpData, waiting for the answer, and putting the result into a sheet.

    With regards to opening password protected VBA code, a google or stackoverflow search should give you your answer.

    0 讨论(0)
  • 2020-12-09 07:23

    I've found that changing something in the BDH formula would cause a refresh. Find and replace the = sign would do the tick.

    Public Sub Recalc()
        Dim ws As Worksheet, FormulaCells As Range, c As Range
        Application.Calculation = xlCalculationManual
        For Each ws In ThisWorkbook.Worksheets
            On Error Resume Next
            ws.Activate
            Set FormulaCells = ws.UsedRange.SpecialCells(xlCellTypeFormulas).Cells
            If Err = 0 Then
                For Each c In FormulaCells
                    c.Formula = Replace(c.Formula, "=", "=")
                Next 'c
            Else
                Err.Clear
            End If
        Next 'ws
        Application.Calculation = xlCalculationAutomatic
    End Sub
    
    0 讨论(0)
提交回复
热议问题