VBA脚本可以读取SAP GUI错误吗?

时间:2016-11-10 15:10:54

标签: vba sap-gui

我没有希望,但我想知道是否有办法让vba脚本识别SAP GUI引发的错误。例如,如果某个交易被另一个用户锁定 目前,如果弹出这个错误,脚本就不会想到它,并继续到下一行(这通常是错误的,因为我按下它的按钮还没有存在)。 如果可能,我想在下一行之前识别该错误,以便用户可以修复它。

在某些情况下,如果做了变通办法,我会让我的脚本承担错误,加上on error resume next,但这会让我感到畏缩,并且不适用于所有情况。

示例:

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

为了清楚起见,我试图找到类似的东西:

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

0 个答案:

没有答案