0

Currently running into an error problem: when migrating orders in SAP GUI through VBA, it might be that an order needs reconfirmation. However, this is not always the case.

I've already build in an error loop in the beginning of the code, so I don't get the object errors anymore. However, I'd like the VBA to CHOOSE between 2 outcomes.

I have built this code (which will cause to go to the next order, if there is an error):

'Press "full delivery (build a if function that if field delivery exists and is >1, press f6)
If Session.findById("wnd[0]/usr/tbl/SAPAPO/SAPLATP4CTR_FINAL/txt/SAPAPO/ATP4CSD-BMNGL[6,0]").Text <> "" Then
    Session.findById("wnd[0]/tbar[1]/btn[6]").press
End If

Then, if it is not in that screen, it should just check whether it still is in the original screen:

If Session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\01/ssubSUBSCREEN_BODY:SAPMV45A:4400/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-WERKS[11,0]").Text <>"" then
    'Save order
    Session.findById("wnd[0]/tbar[0]/btn[11]").press
End if

Unfortunately, this causes an error if it does not go to the Delivery screen (it just stays in the regular order screen). The thing I want it to do then, is to go through with the code.

Is there some way where I can determine in which screen I'm currently, so that VBA takes an action on that?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Thijsk
  • 103
  • 1
  • 3
  • 15
  • I don't understand exactly how SAP is behaving here to create this issue. Does it open another window unexpectedly? Is it not completing the task you expect after pushing the button due to an error? – Josh Jan 23 '19 at 22:53
  • 1
    The answer here was very helpful to me some time ago and may very well be part of the solution... https://stackoverflow.com/questions/33194893/sap-error-handling-by-sap-gui-scripting – Josh Jan 23 '19 at 22:54

1 Answers1

1

You could try the following.

for example:

If Session.findById("wnd[0]").text = "Delivery screen" then 
...
end if

You would have to use the real screen name instead of "Delivery screen".

Regards, ScriptMan

ScriptMan
  • 1,580
  • 1
  • 9
  • 9