Skip to Content
0
Jul 03 at 09:07 AM

How can I open next Sap session when current is running using VBA

156 Views Last edit Jul 03 at 01:13 PM 2 rev

Hello All

I have problem to find VBA code to open new Sap window when current session is running

I am working in SAP and for example running transaction and in this time I want to run macro with recorded Sap session

Maybe it explain better my problem

I need code which copy this action - transaction is running end on left top Sap screen I choosing “New GUI window” clicking and new window appears

It’s code which I use code waiting until running session is off and start new window

I am looking for code that open sew window immediately

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

session.CreateSession

Do

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

If sapCon.Sessions.Count > nSessions Then Exit Do

Loop

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

End Sub