I'm not hopeful, but I'm wondering if there is a way to for a vba script to identify what error is being thrown by SAP GUI. For example, if a transaction is locked by another user.
Currently, if this error pops up, the script thinks nothing of it, and continues to the next line (which normally errs then because whatever button I'm having it press doesn't exist yet).
If possible, I'd like to identify that error before the next line, so the user can fix it.
In some cases, if done workarounds where I'll have my script assume the error, coupled with an on error resume next
but that makes me cringe, and doesn't work for all situations.
Example:
For Each cell In Range("D:D")
If cell.Value = "" Then Exit For
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010/ctxtMAPL-MATNR[2," & 4 & "]").Text = cell.Value
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010/txtMAPL-PLNAL[0," & 4 & "]").Text = groupctr
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010/ctxtMAPL-WERKS[3," & 4 & "]").Text = plant
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position = i + 1
'If a duplicate entry is found, an SAP message box pops up. The script then closes the message box. If no message box pops up,
'the script errors when trying to close it. Therefore, an "error" means the item was sucesfully added.
On Error Resume Next
session.findById("wnd[2]/tbar[0]/btn[0]").press
Next cell
For clarity, I'm trying to get to something like:
On Error Goto ErrHndl
'...my code...
exit sub
ErrHdnl:
Select Case SAPErrCode
Case [ExCode1]
'do things for this error type
Case [ExCode2]
'do different things for this error type