Skip to Content
avatar image
Former Member

INITIAL FILTER IN AFO VBA

Hi Experts,

I would like to filter datasource before open workbook with VBA in AFO

Im trying yo filter a datasource with Workbook_SAP_Initialize()

CODE:

Public Sub Workbook_SAP_Initialize()

lresult = Application.Run("SAPSetFilter", "DS_1", "ACAUDIT", "CREP_TARJ", "INPUT_STRING")

End Sub


The same code execute with botton work but with the initialize of workbook not work.

Thank you all

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    May 18, 2017 at 08:24 AM

    Hi!

    In the code of VBA you have to refresh before the code of the filter:

    Public Sub Workbook_SAP_Initialize()


    Application.Run("SAPExecuteCommand", "Refresh.ActualSheet")

    lresult = Application.Run("SAPSetFilter", "DS_1", "ACAUDIT", "CREP_TARJ", "INPUT_STRING")

    End Sub

    Thank you

    Add comment
    10|10000 characters needed characters exceeded

  • May 16, 2017 at 09:24 AM

    Just from help:

    "Callback 'Workbook_SAP_Initialize' has to be defined in the 'ThisWorkbook' section of the VBA editor."

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 16, 2017 at 09:25 AM

    YES, its defined in this section.

    Thank you

    Add comment
    10|10000 characters needed characters exceeded

  • May 18, 2017 at 03:47 PM

    Hi Javier,

    I don't understand why you want to do this filtering using VBA. Without code you can use BW variables, so the end user can set the restriction. The variable may be based on authorization. Variables have the advantage that you have one implementation that works for all workbooks and queries that contain the variables. VBA code has to be replicated in all relevant workbooks.

    Regards,

    Gregor

    Add comment
    10|10000 characters needed characters exceeded