Skip to Content
Jun 08, 2021 at 04:42 PM

VBA Scripting - How to script SAPGUI logon WITHOUT SSO?



  • Root Cause: Our unit has transitioned to mandatory Single Sign-On (SSO) and deactivated/deleted the non-SSO connection.
  • What I know: I can manually right click (or Shift+Enter) to get to the Context Menu of the SSO connection in order to "SNC Logon without Single Sign-On".
  • What I need: I have a script that uses a protected ID/pw to run a transaction that I don't want all 200 people to have full access to so I need to be able to have the code open the non-SSO connection on any user's computer.

My question: How can I script the right-click action on the SAPGUI logon pad?

My code is here:

  • "PAG - North American AG Production (006)" = non-SSO connection (this was deactivated)
  • "PAG - North American AG Production (SSO)" = SSO connection Dim SapGui
    Dim Applic
    Dim Connection
    Dim Session
    Dim WSHShell

    Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", vbNormalFocus

    Set WSHShell = CreateObject("WScript.Shell")

    Do Until WSHShell.AppActivate("SAP Logon ")
        Application.Wait Now + TimeValue("0:00:01")
    Set WSHShell = Nothing
    Set SapGui = GetObject("SAPGUI")
    Set Applic = SapGui.GetScriptingEngine
    Set Connection = Applic.OpenConnection("PAG - North American AG Production (006)", True)
    Set Session = Connection.Children(0)