Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A



I am trying to set the filters in my workbook using VBA code. I am using the code below, however, the SAPSetFilter call returns a result of 0 (i.e. fails). The technical name is correct and the value is valid. I can get the SAPSetVariable call to work correctly for the fields that are prompts. I have tried many searches but do not seem to be able to work it out.

Any help would be greatly appreciated.



dataSourceAlias = Application.Run("SAPGetCellInfo", Excel.ActiveWorkbook.Sheets("InventoryData").Cells(1, 1), "DATASOURCE")

    lResult = Application.Run("SAPSetRefreshBehaviour", "Off")

    lResult = Application.Run("SAPExecuteCommand", "PauseVariableSubmit", "On")

    lResult = Application.Run("SAPSetVariable", "Calendar Month/Year From", "01.2014", "INPUT_STRING", dataSourceAlias)

    lResult = Application.Run("SAPSetVariable", "Calendar Month/Year TO", "08.2014", "INPUT_STRING", dataSourceAlias)

    PlantSel = "1000"

    lResult = Application.Run("SAPSetVariable", "Plant (Selection Options, Optional)", PlantSel, "INPUT_STRING", "DS_1")

'''''''''''''''''All above code works ok''''''''''''''

''''''''''''''''the line below returns a value of 0'''''''''''''''''''''

    lResult = Application.Run("SAPSetFilter", dataSourceAlias, "0MATERIAL", "200", "KEY")



    lResult = Application.Run("SAPExecuteCommand", "PauseVariableSubmit", "Off")

    lResult = Application.Run("SAPSetRefreshBehaviour", "On")

Former Member
Former Member replied

Hi Martin,

Thanks for your assistance.

I ran your code, and the SAPSetFilter command actually worked. It was the same as my other code except I was the following line

lResult = Application.Run("SAPExecuteCommand", "PauseVariableSubmit", "On")

When I remove this line from the code above the SAPSetFilter command works. My understanding of this line was that it just stopped the workbook from refreshing the filters hence allowing multiple filters to be changed before refreshing the data. It seems this is not the case.

Any comments appreciated.



0 View this answer in context

Helpful Answer

Not what you were looking for? View more on this topic or Ask a question