Skip to Content
author's profile photo Former Member
Former Member

Automatic Logon to BEx

Hi Guru's

Can any one solve my problem that i have created workbook and send it to user now user dont like to open workbook and then open bex tool bar and go for refresh. So by uisng VBA we can write code for Automatic logon i.e when opening the workbook it will automatically opens the BEx tool bar so it is more useful for users.

Please anybady across this type of problems send me the code and steps.

Thanks in Advance...


Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Nov 10, 2006 at 10:18 AM


    Functions 1 and 2 can be combined along with the following code to establish a connection with the server:

    Public Function LogonToYourBW()

    ' create Logon & RFC-Handle

    logonToBW = False ‘ clear connect Flag the flag can be used to find out if connected or not

    'load SAP functionality by opening BEX file ( use your installation path)

    Workbooks.Open (“c:\sappc\bw\sapbex.xla”)

    With Run("sapbex.xla!sapbexGetConnection") ‘ call the connection

    ' Set the params for Auto logon

    .client = “YOUR CLIENT NO”

    .user = “YOUR BW USER”

    .Password = “YOUR BW PWD” ‘ I recommend to create a dummy reporting user for this task


    .SystemNumber = “YOUR SYSTEM NO” ‘

    .ApplicationServer = “YOUR SERVER Name OR IP-ADDRESS”

    .UseSAPLOgonIni = FALSE 'important for automatic connection

    .logon 0, True ‘ This will provide a dialog to appear

    If .IsConnected <> 1 Then

    .logon 0, False

    If .IsConnected <> 1 Then Exit Function


    Set g_oFunction = CreateObject("SAP.Functions")

    Set g_oFunction.Connection = g_oConnection

    End If

    End With

    Run "sapbex.xla!sapbexinitConnection" ‘ this will enable the connection you just created

    logonToBW = True

    End Function

    Function 7 can be used to refresh queries in an active workbook. To refresh all queries, set the first parameter to True and use the following code:

    If Run("sapbex.xla!SAPBEXrefresh", True) = 0 Then


    MsgBox " Error in Refresh"

    To refresh a single query, reference a valid cell in the query (navigation or filter area or result area)

    ‘Set the values for Variables

    Dim rngVar as Range

    Set rngVar = YOUR_VARIABLE_SHEET.Range(“A2:H3”)

    Run "SAPBEXsetVariables", rngVar

    If Run("SAPBEX.xla!SAPBEXrefresh", False, ActiveSheet.Range("C7")) = 0 Then


    MsgBox "Error in Refresh”

    End If



    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member


      I'm relatively new to this so please excuse my lack of knowledge.

      I tried to implement the above code, but when I run the function, the SAP Logon screen still pops up. I'm not positive that my applicationserver and systemnumber parameters are correct - could this be the cause?

      Username and password parameters are successfully passed.



Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.