Skip to Content

How to find Transaction Screen Name for use with AppActivate

Feb 02 at 08:16 AM


avatar image

Hi all

I'm using a VBA script to create reservations in MB21. The amount of materials to be in the reservation can vary so I've set up a loop to go thru the list.

I then need to reactivate the SAP screen so it can save it.

Problem is the screen that the script took over does not have the same name as the create reservations screen. It is usually the Goods Movement screen that the script takes over, but that is not always the case.

See script below:

Sub Create_201_Reservations_For_7038251()

Sheets("Cost Centres").Select If Cells(3, 2).Value = "" Then

Sheets("Working Sheet").Select Range("C62").Value = "NIL"



Sheets("Cost Centres").Activate Dim App, Connection, session As Object

Set SapGuiAuto = GetObject("SAPGUI")

Set App = SapGuiAuto.GetScriptingEngine

Set Connection = App.Children(0) Set session = Connection.Children(0)

session.findById("wnd[0]").resizeWorkingPane 228, 35, False

session.findById("wnd[0]/tbar[0]/okcd").Text = "/nmb21"

session.findById("wnd[0]").sendVKey 0 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' session.findById("wnd[0]/usr/ctxtRM07M-BWART").Text = Cells(1, 2).Value 'movement type

session.findById("wnd[0]").sendVKey 8

session.findById("wnd[1]/usr/txtRKPF-WEMPF").Text = Cells(1, 13).Value 'recipient

session.findById("wnd[1]/usr/subBLOCK:SAPLKACB:1001/ctxtCOBL-KOSTL").Text = Cells(1, 1).Value 'cost centre

session.findById("wnd[0]").sendVKey 0 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim z As Integer

Dim c As Integer

c = Range("C2").Value

For z = 3 To c session.findById("wnd[0]").sendVKey 8

session.findById("wnd[0]/usr/ctxtRESB-MATNR").Text = Cells(z, 1).Value 'material number

session.findById("wnd[0]/usr/txtRESB-ERFMG").Text = Cells(z, 2).Value 'amount

session.findById("wnd[0]/usr/ctxtRESB-LGORT").Text = "U801" 'plant

session.findById("wnd[0]/usr/ctxtRESB-LGORT").Text = "0100" 'sloc

session.findById("wnd[0]/usr/txtRESB-ABLAD").Text = Cells(2, 13).Value 'unloading point

Next z

AppActivate ("Goods Movement") ''''needs to be Create Reservation: New Item 00xx''''

session.findById("wnd[0]").sendVKey 11 End If End Sub

How can I get the script to retrieve the name of the transaction screen being used, so i can plant that into the script when it comes time to use AppActivate?



10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers