on 01-09-2014 10:55 AM
Hi Emil,
Do you want to keep at least one session (modus) open and close the other? If that is the case then try the following:
Option Explicit
Sub CloseAllExceptOneSession()
'require early binding to C:\Program Files\SAP\FrontEnd\SAPgui\sapfewse.ocx
Dim sapGui As SAPFEWSELib.GuiApplication
Dim sapCon As SAPFEWSELib.GuiConnection
Dim sapSession As SAPFEWSELib.GuiSession
Set sapGui = GetObject("sapgui").GetScriptingEngine
Set sapCon = sapGui.Children(0)
If sapCon.Children.Count > 1 Then
Dim i As Long
For i = sapCon.Children.Count - 1 To 1 Step -1
Set sapSession = sapCon.Children(i)
sapSession.FindById("wnd[0]").Close
Next i
Else
MsgBox "Only one session open now"
End If
Set sapSession = Nothing
Set sapCon = Nothing
Set sapGui = Nothing
End Sub
Thanks,
Sayuti
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fantastic - both works fine. Thank you.
Regards,
Emil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Emil,
I would solve this issue as follows:
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
while connection.children.count > 1
Set asession = connection.Children(1)
asession.findbyid("wnd[0]").close
on error resume next
asession.findById("wnd[1]/usr/btnSPOP-OPTION1").press
on error goto 0
wend
Regards,
ScriptMan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Emil,
In such cases, one can proceed as follows:
If Not IsObject(myApplication) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set myApplication = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(myConnection) Then
Set myConnection = myApplication.Children(0)
End If
while myConnection.children.count > 1
Set mySession = myConnection.Children(1)
mySession.findbyid("wnd[0]").close
on error resume next
mySession.findById("wnd[1]/usr/btnSPOP-OPTION1").press
on error goto 0
wend
Regards,
ScriptMan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.