Page 1 of 1

[Excel] TM1 Get Value from Cube VBA

Posted: Tue Aug 27, 2019 8:52 am
by HighKeys
Hello,

how can i get a value from a cube in VBA?

I tried to send the DBR Formula via "Application.Run" but it seems not to work.

Code: Select all

Function GetNumberFromTM1(Server As String, Cube As String, ParamArray arg() As Variant) As Long

    ReDim Z(UBound(arg()))
    For i = 0 To UBound(arg())
        Z(i) = arg(i)
    Next i
    
    send = "DBR(" & Chr(34) & Server & ":" & Cube & Chr(34) & ";"
    
    For i = 0 To UBound(Z())
        
        'Gerade Param elemente
       ' If i Mod 2 = 0 Then
            send = send & Chr(34) & Z(i) & Chr(34) & ";"
      '  Else
            
      '  End If
        
    Next i

    GetNumberFormTM1 = Application.Run(send)

End Function
Thanks for your help!

Re: [Excel] TM1 Get Value from Cube VBA

Posted: Tue Aug 27, 2019 9:00 am
by Alan Kirk
You don't put the arguments to DBR in brackets like that when you are using Application.Run. DBR is the first argument (in quotes), and the other arguments are separated by commas.

Re: [Excel] TM1 Get Value from Cube VBA

Posted: Tue Aug 27, 2019 11:04 am
by HighKeys
Hello,

thanks! i was too deep in the formula when i coded this...

Code: Select all

Function GetNumberFromTM1(Server As String, Cube As String, ParamArray arg() As Variant) As Long

    ReDim Z(UBound(arg()))
    For i = 0 To UBound(arg())
        Z(i) = arg(i)
    Next i
    
    send = Chr(34) & "DBR" & Chr(34) & "," & Chr(34) & Server & ":" & Cube & Chr(34) & ","
    
    For i = 0 To UBound(Z())
        

        If i = UBound(Z()) Then
            send = send & Chr(34) & Z(i) & Chr(34)
        Else
            send = send & Chr(34) & Z(i) & Chr(34) & ","
        End If
        
    Next i

    GetNumberFormTM1 = Application.Run(send)
Now i changed the formatting from "send" to the Application.Run syntax, but still it says the macro is missing.

Any idea?

Thanks you so much!


Edit:

Here is the working Code:

Code: Select all

Function GetNumberFromTM1(Server As String, Cube As String, ParamArray arg() As Variant) As Long

    ReDim Z(UBound(arg()))
    For i = 0 To UBound(arg())
        Z(i) = arg(i)
    Next i
    
    send = "DBR(" & Chr(34) & Server & ":" & Cube & Chr(34) & ","
    
    For i = 0 To UBound(Z())
        

        If i = UBound(Z()) Then
            send = send & Chr(34) & Z(i) & Chr(34) & ")"
        Else
            send = send & Chr(34) & Z(i) & Chr(34) & ","
        End If
        
    Next i

    t = Application.Evaluate(send)
    GetNumberFromTM1 = t
End Function
Thanks for the Help!