cancel
Showing results for 
Search instead for 
Did you mean: 

Problems running a script with two sessions opened using VBS

0 Kudos

This is my Script - I have two sessions opened - everytime I am ont he second window where the second session is opened and asked on which sessions is my CK11N i get seesion number 2 -

I do call the script - and fails because it goes to the first session where is my CK74N that is session Number 1

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]").maximize

session.findById("wnd[0]/usr/sub/1/tabsREITER/tabpTERM/ssub/1/2/4/ctxt[0]").text = "11/01/2018"

session.findById("wnd[0]/usr/sub/1/tabsREITER/tabpTERM/ssub/1/2/4/ctxt[1]").text = "12/31/9999"

session.findById("wnd[0]/usr/sub/1/tabsREITER/tabpTERM/ssub/1/2/4/ctxt[2]").text = "11/01/2018"

session.findById("wnd[0]/usr/sub/1/tabsREITER/tabpTERM/ssub/1/2/4/ctxt[3]").text = "11/01/2018"

session.findById("wnd[0]/usr/sub/1/tabsREITER/tabpTERM/ssub/1/2/4/ctxt[3]").setFocus

session.findById("wnd[0]/usr/sub/1/tabsREITER/tabpTERM/ssub/1/2/4/ctxt[3]").caretPosition = 10

session.findById("wnd[0]/tbar[1]/btn[0]").press

How can I make the script work on session 2 when i call the script from my program?

Thank you!

Accepted Solutions (0)

Answers (1)

Answers (1)

script_man
Active Contributor
0 Kudos

Hi Maria,

try it like this:

...
Set session = connection.Children(1)
...

Regards,

ScriptMan