on 05-12-2014 11:02 AM
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.