cancel
Showing results for 
Search instead for 
Did you mean: 

Addrees to certain session

Former Member
0 Kudos

Hi everbody,

now I'm also a meber of this blog.

I've a Problem to address a certain SAP session via VBA code.

I've written a VBA code to control and getting some Information from the MM003 (Material) but VBA looks always to the first SAP session.

I start the VBA code with GUIXT in MM03. But if this session not the first session, the code try to operate from the first one.

Because of the reason, that I'm not able to insert the copy of my code here I gave the textfile enclose.

Thank you in advance.

Michael

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

My method for dealing with this is always launch a new instance of SAP and then use the code below to get the last window opened


    Set SapGuiAuto = GetObject("SAPGUI")

    Set SapApp = SapGuiAuto.GetScriptingEngine

    Set SapCon = SapApp.Children(SapApp.Children.Count - 1)

    Set Session = SapApp.Children(SapApp.Children.Count - 1).sessions(SapApp.Children(SapApp.Children.Count - 1).sessions.Count - 1)

Former Member
0 Kudos

Hello Michael,

the session in your code is being set to the first "child" of the connection (session = sapConnection.Children(0)).

In order to have a certain session being selected, you need to identify it and there are a couple of approaches to do this.

One of the simplier ones would be to get the session in which a certain transaction is being executed. the property "transaction" of the GuiSessionInfo object (which is a member of any GuiSession) gives you this information.

What’s left to do is, to iterate over all sessions (aka "children") of a GuiConnection, compare the current transaction being executed with the desired one (this would be „MM03“ in your case, if I’m correct) and if it the desired one, you have the session you need.

Kind regards

Alkis

holger_khn
Contributor
0 Kudos

Hello.

I Have add an guidance how To prepare an Macro-entblödet Excel Template To select an specific SAP Session for Exekution.

I Gutes Review my Code will Five you some Idea how To achieve such requirement.

Best regards

Holger