Hi all,
I am quite new to the sap automatization scene but have accomplished quite alot in the last few months due to this forum 😊
However, For my last need i cannot seem to find a solution. That is why i am going to post my first topic here.
What i want to accomplish:
I am using a single sign on system so i do not need to give any user name information. However, i have different systems in my system.
When i use my macros it will log into the one that is open.
Now when i have the need to log into a different system (Defined in the saplogon ofcourse) by Create a new session.
Now i only need to give the order to pick my desired system, but have no clue how.
The code i use for the new session:
[code]
Session_number_max = 6 'MAx
ReDim session_number_(Session_number_max)
On Error GoTo NeedCRM
Set SapGuiAuto = GetObject("SAPGUI")
Set sapp = SapGuiAuto.GetScriptingEngine
On Error GoTo NeedCRM
Set Connection = sapp.Children(0)
Set session = Connection.Children(0)
'------------------------------------------- Lookup -------------------------------------------------------------
session_number_all = Connection.Children.Count - 1
For i = 1 To Session_number_max
session_number_(i) = 0
Next
For session_number = 0 To session_number_all
Set session = Connection.Children(Int(session_number))
session_number_(session.info.sessionnumber) = session.info.sessionnumber
Next
If session_number_all < Session_number_max - 1 Then
session.createsession
Do
waitTill = Now() + TimeValue("00:00:01")
While Now() < waitTill
DoEvents
Wend
If Connection.Children.Count - session_number_all >= 2 Then Exit Do
Loop
On Error Resume Next
Error_number = 1
For session_number = 0 To session_number_all + 1
Err.Clear
Set session = Connection.Children(Int(session_number))
If Err.Number > 0 Or Err.Number < 0 Then Exit For
If session_number_(session.info.sessionnumber) = 0 Then
Error_number = 0
Exit For
End If
'session.findById("wnd[0]").iconify 'So you can send another SAP session in the task bar.
Next
On Error GoTo 0
Else
MsgBox "New session is not possible."
End If
'------------------------------------------- new session connect -------------------------------------------------------------
If Error_number = 0 Then
With session
[/code]
Hopefully someone could help me connect to my defined system,
Thanks alot 😊
Robert.