vbasap-gui

Automatically close if SAP status message error captured


How do I stop a SAP GUI script if there any status messages are captured.

I created a SAP GUI script recording and Excel macro for automation.
It works if there's any data collected.
If there's no data collected and will have status bar then the script will error.

I tried to create some code if the status error show up, the script will automatically close. Seems I only can make it work if the error is for "No items selected (see long text)".

Other status errors show up, so I'm thinking to make the status bar capture the whole error if possible.

If session.findById("wnd[0]/sbar").Text = "No items selected (see long text)" Then
    Exit Sub
End If

Solution

  • You can check for the messagetype of the status bar. If it is E then you've got an error.

    Instead checking for the text like in your code you check for the messagetype

    If session.findById("wnd[0]/sbar").MessageType= "E" Then
      ' Whatever code is needed here
    Exit Sub
    
    End If