希望はありませんが、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