cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Activate a session via Gui scripting

Former Member
0 Likes
10,101

Hi,

how to activate an active SAP-session via Gui Scripting or maybe a workaround?

There are some SAP sessions running and I want to activate a certain one of them.

I tried to activate a session with:

AppActivate session.findById("wnd[0]").Text

but, as we know, if there are the same task names in Task Manager, the function will start any one of them.

Any idea?

Edited by: Stefan Benkö on Feb 9, 2009 7:07 AM

View Entire Topic
Former Member
0 Likes

Dear Casmir,

I use the following code:

suFound = False

suError = False

sgSystem = Trim(Cells(Target.Row, scSysCol))

sgClient = Trim(Cells(Target.Row, scCliCol))

sgUser = Trim(Cells(Target.Row, scUsrCol))

sgPW = Trim(Cells(Target.Row, scPwdCol))

suError = True

suError = Not ssApplication

If suError Then GoTo StopSub

For Each suConnection In sgApplication.Connections

suSysName = suConnection.Description

If suSysName = sgSystem Then

For Each suSession In suConnection.sessions

suSysClient = suSession.info.client

If suSysClient = sgClient Then

AppActivate suSession.findById("wnd[0]").Text

'Aktive Instanz herausfinden, SID/Client checken

Set suAkt = sgApplication.ActiveSession()

suAktName = suAkt.Parent.Description

suAktClient = suAkt.info.client

If sgSystem <> suAktName Or sgClient <> suAktClient Then

If Not suFound Then

suFound = True

AppActivate "Microsoft Excel"

A = MsgBox(sgSystem & " - " & sgClient & " NOT selectable", vbOKOnly + vbCritical + vbDefaultButton1, "SAP Automation")

End If

Else

suFound = True

End If

Exit For

End If

suSysClient = ""

Next

End If

If suFound Then Exit For

suSysName = ""

Next

As you can see, I got at that point all the necessary session and connection data.

There are several SAP-Tasks open and what I want is to get a specific one as active window on my screen. That doesn't work if the sessions have the same Task-name, for instance "SAP Easy Access". Because Windos is not albe to find the right SAP-task - they have the same name - and it takes usally the wrong one of them. Thats my problem.

Many Thanks for your Help