on 2022 Jul 03 10:07 AM
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
Request clarification before answering.
Thank you Stefan
It works properly
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
gzahaczewski
Hello Grzegorz,
try the Busy method to check if you can use a session or not.
Best regards
Stefan
Set SapGuiAuto = GetObject("SAPGUI")
If Not IsObject(SapGuiAuto) Then
Exit Function
End If
Set app = SapGuiAuto.GetScriptingEngine
If Not IsObject(app) Then
Exit Function
End If
'-Get all connections-------------------------------------------------
Set CollCon = app.Connections()
If Not IsObject(CollCon) Then
Exit Function
End If
'-Loop over connections-----------------------------------------------
For i = 0 To CollCon.Count() - 1
Set oCon = app.Children(CLng(i))
If Not IsObject(oCon) Then
Exit Function
End If
'-Get all sessions of a connection----------------------------------
Set CollSes = oCon.Sessions()
If Not IsObject(CollSes) Then
Exit Function
End If
'-Loop over sessions------------------------------------------------
For j = 0 To CollSes.Count() - 1
Set oSes = oCon.Children(CLng(j))
If Not IsObject(oSes) Then
Exit Function
End If
If oSes.Busy() = vbFalse Then
'-If you can use the session place your code here
End If
Next
Next
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.