Hello.
Check if statusbar messagetype is <> "Error":
Sub run() If Not IsObject(AppSapGui) Then Set SapGuiAuto = GetObject("SAPGUI") Set AppSapGui = SapGuiAuto.GetScriptingEngine End If If Not IsObject(Connection) Then Set Connection = AppSapGui.Children(0) End If If Not IsObject(Session) Then Set Session = Connection.Children(0) End If If IsObject(WScript) Then WScript.ConnectObject Session, "on" WScript.ConnectObject AppSapGui, "on" End If Session.FindById("wnd[0]").maximize For x = 5 To 5000 If Cells(x, 1) = "" Then Exit For Session.FindById("wnd[0]/tbar[0]/okcd").Text = "/nMM03" Session.FindById("wnd[0]").sendVKey 0 Session.FindById("wnd[0]/usr/ctxtRMMG1-MATNR").Text = Cells(x, 1) Session.FindById("wnd[0]").sendVKey 0 Session.FindById("wnd[1]/tbar[0]/btn[0]").press Session.FindById("wnd[1]/usr/ctxtRMMG1-WERKS").Text = "7351" Session.FindById("wnd[1]/usr/ctxtRMMG1-LGORT").Text = Cells(x, 4) 'dep Session.FindById("wnd[1]/tbar[0]/btn[0]").press If Session.FindById("wnd[0]/sbar").MessageType <> "E" Then Cells(x, 2) = Session.FindById("wnd[0]/usr/tabsTABSPR1/tabpSP20/ssubTABFRA1:SAPLMGMM:2000/subSUB1:SAPLMGD1:1005/txtMAKT-MAKTX").Text Cells(x, 5) = Session.FindById("wnd[0]/usr/tabsTABSPR1/tabpSP20/ssubTABFRA1:SAPLMGMM:2000/subSUB2:SAPLMGD1:2701/txtMARD-LGPBE").Text 'position Session.FindById("wnd[0]").sendVKey 0 Cells(x, 3) = Session.FindById("wnd[0]/usr/tabsTABSPR1/tabpSP30/ssubTABFRA1:SAPLMGMM:2000/subSUB3:SAPLMGD1:3002/txtMARD-LABST").Text Session.FindById("wnd[0]/tbar[0]/btn[3]").press End If Next End Sub
Hope this help you.
Best regards,
Holger