I haven't found many articels on this yet on stackoverflow so i will elaborate a bit more by giving the necessary background info.
I'm using the SAP BO Analysis for Excel add-in through which i'm retrieving data in Excel from SAP BW.
The Analysis add-in comes with a GUI through which you can enter variables in the query (so called prompts).
It additionally has an VBA API so you can set the variables through VBA.
My big problem is that the setting of variables through VBA only seems to work when i have set atleast 1 prompt through the GUI :S
Below is my full VBA code. It's inspired on http://precisionstudio.net/uploads/3/0/5/0/3050843/sap_instructorhandbook.pdf & http://scn.sap.com/community/businessobjects-analysis-ms-office/blog/2011/06/26/can-you-use-vba-with-businessobjects-analysis-find-out-here
The Dims lResul, lResult & lResultt return 0, but when i manually fill in a value in the GUI prompt and re-run the VBA macro, it works (returns 1)... it fills in the other values. Very strange.
Has somebody encoutered same issues and know the way out?
Many thanks in advance
Private Sub EnableAnalysisOffice()
Dim addin As COMAddIn
For Each addin In Application.COMAddIns
If addin.progID = "SBOP.AdvancedAnalysis.Addin.1" Then
If addin.Connect = False Then addin.Connect = True
End If
Next
End Sub
Private Sub Workbook_Open()
Call EnableAnalysisOffice
Call MyGetData
End Sub
Public Sub MyGetData()
Dim Iret As Long
Dim lResul As Long
Dim lResult As Long
Dim lResultt As Long
Iret = Application.Run("SAPLogon", "DS_1", "200", "myUser", "myPassword")
MsgBox (Iret)
Call Application.Run("SAPSetRefreshBehaviour", "Off")
Call Application.Run("SAPExecuteCommand", "PauseVariableSubmit", "On")
'Select data based on WBS
'lResul = Application.Run("SAPSetVariable", "0S_WBSE", Worksheets("Prompt Values").Range("A2").Value, "INPUT_STRING", "DS_1")
'MsgBox (lResul)
'Select data based on Employees
lResult = Application.Run("SAPSetVariable", "YEMPLSEL", Worksheets("Prompt Values").Range("A5").Value, "INPUT_STRING", "DS_1")
MsgBox (lResult)
'Document Date
lResultt = Application.Run("SAPSetVariable", "YDOCUMENT_DATE", ">=01\-01\-2015", "INPUT_STRING", "DS_1")
MsgBox (lResultt)
Call Application.Run("SAPExecuteCommand", "PauseVariableSubmit", "Off")
Call Application.Run("SAPSetRefreshBehaviour", "On")
'Call Application.Run("SAPExecuteCommand", "Refresh")
End Sub
addin.Connect = True- ChipsLetten