Skip to Content
avatar image
Former Member

Variable declaration in sap logon

Dear Experts,

Please note that I’m new in VBA and SAP GUI SCRITPING. I just read few discussion about with SAP LOGON, most of users use early binding to establish connection with SAP.

As far I'm concerned I use late binding. Please find below:

Set Connection = GetObject("SAPGUI").GetScriptingEngine.Children(0)

If Not IsObject(SAPGUIApp) Then

   Set SapGuiAuto = GetObject("SAPGUI")

   Set SAPGUIApp = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(Connection) Then

   Set Connection = SAPGUIApp.Children(0)

End If

If Not IsObject(SAP_Session) Then

   Set session = Connection.Children(0)

End If

If IsObject(WScript) Then

   WScript.ConnectObject session, "on"

   WScript.ConnectObject SAPGUIApp, "on"

End If

I would like to use OPTION EXPLICIT in my codes, but that requires also Variable declaration for that part. I already add SAP GUI SCRIPTING API library in references, bo still i don't know objects there.

Can anyone help me out with that variable declaration?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    May 12, 2014 at 10:52 AM

    Hello Tomasz,

    welcome in the SAP GUI Scripting forum.

    You add at first the SAP GUI Scripting API library as reference to your VBA project from the Tools menu.

    Now you can use this code with explicit variable declaration:

    Option Explicit

    Sub Test()

      On Error Resume Next

      Dim SapGuiAuto As Object

      Dim SAPGUIApp As SAPFEWSELib.GuiApplication

      Dim Connection As SAPFEWSELib.GuiConnection

      Dim Session As SAPFEWSELib.GuiSession

      Set SapGuiAuto = GetObject("SAPGUI")

      If SapGuiAuto Is Nothing Then

        Exit Sub

      End If

      Set SAPGUIApp = SapGuiAuto.GetScriptingEngine

      If SAPGUIApp Is Nothing Then

        Exit Sub

      End If

      Set Connection = SAPGUIApp.Children(0)

      If Connection Is Nothing Then

        Exit Sub

      End If

      Set Session = Connection.Children(0)

      If Session Is Nothing Then

        Exit Sub

      End If

      'Your Code here

    End Sub

    Good luck.

    Cheers

    Stefan


    001.JPG (46.3 kB)
    Add comment
    10|10000 characters needed characters exceeded