cancel
Showing results for 
Search instead for 
Did you mean: 

Check other Modus is aktually opend, and close Modus

Former Member
0 Kudos

Hello,

does everyon know a possibility to check if an other Modus is aktually opend.

And if an other Modus is open how can i close the Modus.

I cant find any documentation.

Regards,

Emil

Accepted Solutions (1)

Accepted Solutions (1)

former_member213011
Participant
0 Kudos

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

Answers (2)

Answers (2)

Former Member
0 Kudos

Fantastic - both works fine. Thank you.

Regards,

Emil

script_man
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Scriptman

I use Excel VBA to run the skript.

Application is a reserved Word in VBA

There is an error in the line:

Regards,

Emil

script_man
Active Contributor
0 Kudos

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