Hello Isac,
welcome in the Scripting Languag forum.
You can try this:
'-Begin-----------------------------------------------------------------
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
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]/tbar[0]/okcd").text = "/ose16n"
session.findById("wnd[0]").sendVKey 0
'-End-------------------------------------------------------------------
All you have to do is to set a /o in front of your transaction code. With this prefix you create a new mode. As far as I know it is not possible to set the session number of a new mode, the SAP GUI for Windows allocates the next free number automatically.
If you want to know your session number you can try the following snippet:
For cntSession = 0 To connection.Children.count - 1
Set mySession = connection.Children(CInt(cntSession))
If mySession.Info.Transaction = "SE16N" Then
mySessionNo = mySession.Info.SessionNumber
Exit For
End If
Next
MsgBox mySessionNo
It scans all open sessions and find the first session with the transaction code SE16N.
If you want to know definitely your new session number, scan all sessions before you start your transaction code, do the same after and compare the results.
Let us know your results.
Cheers
Stefan