cancel
Showing results for 
Search instead for 
Did you mean: 

VBA and SAP Logon pad

Former Member
0 Kudos

Hi, I am new to SAP. I have the SAP Logon 740 screen up and need to bind Excel VBA so I can choose which logon to pick and open SAP. My goal is to choose one of my favorites and export some data. My code fails at ...

Set SapGuiAuto = GetObject("SAPGUI") with the error "Automation Error Invalid Syntax".

I have my reference "SAP Remote Function Call Unicode Control" and "SAP GUI Scripting API" added. I connect through Citrix, not sure if that matters.

Sub Test()

   Dim SapGuiAuto As Object

  Dim Application As SAPFEWSELib.GuiApplication

  Dim Connection As SAPFEWSELib.GuiConnection

  Dim Session As SAPFEWSELib.GuiSession

  Dim Window As SAPFEWSELib.GuiModalWindow

  Dim Coll As SAPFEWSELib.GuiCollection

  Set SapGuiAuto = GetObject("SAPGUI")

  If Not IsObject(SapGuiAuto) Then

    Exit Sub

  End If

...

Another option could be login scripts:

I have seen logon scripts, but I don't know where to get all the details...

sapConnection.client = "xxx"

sapConnection.user = "know this"

sapConnection.Language = "EN"

sapConnection.hostname = "xxx"

sapConnection.Password = "know this"

sapConnection.SystemNumber = "x"

sapConnection.Destination = "xxx"

sapConnection.logon

I can see the properties from my connection type,

I have systemId, Message Server, Group/Server, InstanceNumber

I am also trying to get Script Recording and Playback activated, that may not happen.

Any help appreciated.

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

I use a logon script that uses a specifically tailored SAP shortcut that contains the connection IP for the system i'm looking for.  Red line references the location of my shortcut.


Dim objShell

Dim Application

  Set objShell = WScript.CreateObject( "WScript.Shell" )

'open SAP shortcut

  objShell.Run("""C:\Users\p00137\Documents\SCRIPTS\RUN MONTHLY\SAPgui""")

  WScript.Sleep (15000)

'start scripting engine

If Not IsObject(Application) Then

   Set SapGuiAuto = GetObject("SAPGUI")

   Set Application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(Connection) Then

   Set Connection = Application.Children(0)

End If

If Not IsObject(session) Then

   Set session = Connection.Children(0)

End If

If IsObject(WScript) Then

   WScript.ConnectObject session, "on"

   WScript.ConnectObject Application, "on"

End If

  session.findById("wnd[0]/usr/txtRSYST-MANDT").text = "CLIENT GOES HERE"

  session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "USERNAME GOES HERE"

  session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "PASSWORD GOES HERE"

  session.findById("wnd[0]").sendVKey 0

The shortcut utilized is for a target of SAPgui.exe with extension for the IP.  Shortcut needs to be referenced without a file extension type.

That way the script bypasses the logon pad and immediately goes to the activated SAP system where you engage the scripting system for logon.