Skip to Content
Jul 01, 2022 at 06:41 PM

Sap new session from VBA

64 Views Last edit Jul 01, 2022 at 06:43 PM 2 rev

Hello All

I am searching for macro script that opens new session when current session is running

Problem is that macro opens new sesion when its only opened but not makes new session when current session is running exaple transaction after pressing execute button

Thank you for help

My macro below

Private Sub nextSession()

Dim nSessions As Integer

Set SapGuiAuto = GetObject("SAPGUI")

Set SAPApp = SapGuiAuto.GetScriptingEngine

Set sapCon = SAPApp.Children(0)

Set session = sapCon.Children(0)

nSessions = sapCon.Sessions.Count



Application.Wait (Now() + 500 * ms)

If sapCon.Sessions.Count > nSessions Then Exit Do


Set sapSession = sapCon.Sessions.Item(CInt(sapCon.Sessions.Count - 1))

End Sub