on 03-30-2016 3:38 PM
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
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.