0

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
bbadgett
  • 70
  • 1
  • 7
  • Instead of shutting the error up, handle it? Or make some checks, I assume `findById` returns `Nothing` if it does not find anything? – GSerg Nov 10 '16 at 15:15
  • @GSerg Well in the example, there's nothing to handle (In my actual code I don't `on error resume next` as I use the "error" to track valid entries, but that's beside the point). But generally speaking, I need to know what the error (on the SAP side) is so that I can handle it. – bbadgett Nov 10 '16 at 16:34

0 Answers0