Question : Excel VBA Bloomberg function

Im trying to write a simple macro so that the code can paste the bloomberg BDS formula in the worksheet. Everything works fine but when i open the xls in the bloomberg add-on excel, I have to press F2 and Enter in every cell before the BDS formula activated for downloading data. Does anyone know how to solve this problem?

Sub Macro1()

    ActiveSheet.Name = "Result1"
    For i = 1 To 51

    Sheets("Main").Select
    Range("D" & 13 + i).Select
    Selection.Copy
    Sheets("Result1").Select
    Range("A1").Select
    Cells(1, 5 * (i - 1) + 1).Select
   
    ActiveSheet.Paste
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
   
    Range("A2").Select
    Cells(2, 5 * (i - 1) + 1).Select
    ActiveCell.FormulaR1C1 = "OPT_CHAIN"

    Range("A3").Select
    Cells(3, 5 * (i - 1) + 1).Select
    ActiveCell.FormulaR1C1 = "=BDS(R1C,R2C)"
 
    Next i
    End Sub
   
Sub Macro2()

   
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "PX_MID"
 
    Range("B3").Select
    ActiveCell.FormulaR1C1 = "=BDP(R[0]C[-1],R2C)"
    Range("B3").Select
    Selection.Copy
    Range("B4:B2002").Select
    ActiveSheet.Paste
    Range("C2").Select
    ActiveCell.FormulaR1C1 = "VOLUME"
    Range("C3").Select
    ActiveCell.FormulaR1C1 = "=BDP(R[0]C[-2],R2C)"
    Range("C3").Select
    Selection.AutoFill Destination:=Range("C3:C2002")
    Range("D2").Select
    ActiveCell.FormulaR1C1 = "OPT_DELTA"
    Range("D3").Select
    ActiveCell.FormulaR1C1 = "=BDP(R[0]C[-3],R2C)"
    Range("D3").Select
    Selection.AutoFill Destination:=Range("D3:D2002")
    Range("E2").Select
    ActiveCell.FormulaR1C1 = "OPEN_INT"
    Range("E3").Select
    ActiveCell.FormulaR1C1 = "=BDP(R[0]C[-4],R2C)"
    Range("E3").Select
    Selection.AutoFill Destination:=Range("E3:E2002")
    Range("B2:E2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    For j = 1 To 49
    Cells(2, 5 * j + 2).Select
    ActiveSheet.Paste
    Next j
    End Sub

Answer : Excel VBA Bloomberg function

y338,

The code below is a shortened edition of what you provided. There is no need to use 'Select' in VBA, instead simply assign values directly to the required destination.

I think the reason you are have problems is that you have not got a reference to the Bloomberg Add-in in your VBA code. You will need something like this in your VBA macro:

Application.AddIns.Add "add-in_filename here"

Or more simply make sure that you have in the main Excel menu, gone to Tools/Add-ins and checked/ticked the 'Bloomberg' add-in.

Patrick
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
Sub Macro1()
Dim i As Long
    For i = 1 To 51
        Sheets("Main").Cells(i + 13, "D").Copy
        With Sheets("Result1")
            .Cells(1, 5 * (i - 1) + 1).PasteSpecial _
                Paste:=xlPasteValues, Operation:=xlNone, _
                SkipBlanks:=False, Transpose:=False
            .Cells(2, 5 * (i - 1) + 1) = "OPT_CHAIN"
            .Cells(3, 5 * (i - 1) + 1).FormulaR1C1 = "=BDS(R1C,R2C)"
        End With
    Next i
End Sub
   
Sub Macro2()
Dim sourcerange As Range
Dim fillrange As Range
Dim j As Long
   
With Sheets("Result1") 'correct the sheet name to suit
    .Range("B2") = "PX_MID"
    .Range("B3").FormulaR1C1 = "=BDP(R[0]C[-1],R2C)"
    .Range("B3").Copy .Range("B4:B2002")
    .Range("C2") = "VOLUME"
    .Range("C3").FormulaR1C1 = "=BDP(R[0]C[-2],R2C)"
    .Range("C3").Copy .Range("C3:C2002")
    .Range("D2") = "OPT_DELTA"
    .Range("D3").FormulaR1C1 = "=BDP(R[0]C[-3],R2C)"
    .Range("D3").Copy .Range("D3:D2002")
    .Range("E2") = "OPEN_INT"
    .Range("E3").FormulaR1C1 = "=BDP(R[0]C[-4],R2C)"
    .Range("E3").Copy .Range("E3:E2002")
    .Range("B2:E2").Select
    .Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    For j = 1 To 49
        Cells(2, 5 * j + 2).Select
        ActiveSheet.Paste
    Next j
End With

End Sub
Random Solutions  
 
programming4us programming4us