I made the code below:
For x = 4 To 5000 If Cells(x, 2) = "" Then Exit For session.findById("wnd[0]").maximize session.findById("wnd[0]/tbar[0]/okcd").Text = "/nmb22" session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/ctxtRM07M-RSNUM").Text = Cells(x, 2) session.findById("wnd[0]/usr/ctxtRM07M-RSNUM").caretPosition = 0 session.findById("wnd[0]").sendVKey 0 '-----------ITENS------------------------- If Cells(x, 4) = 1 Then session.findById("wnd[0]/usr/sub:SAPMM07R:0521/chkRESB-XLOEK[0,83]").Selected = True session.findById("wnd[0]/tbar[0]/btn[11]").press Cells(x, 3) = session.findById("wnd[0]/sbar").Text End If If Cells(x, 4) = 2 Then session.findById("wnd[0]/usr/sub:SAPMM07R:0521/chkRESB-XLOEK[1,83]").Selected = True session.findById("wnd[0]/tbar[0]/btn[11]").press Cells(x, 3) = session.findById("wnd[0]/sbar").Text End If If Cells(x, 4) = 3 Then session.findById("wnd[0]/usr/sub:SAPMM07R:0521/chkRESB-XLOEK[2,83]").Selected = True session.findById("wnd[0]/tbar[0]/btn[11]").press Cells(x, 3) = session.findById("wnd[0]/sbar").Text End If If Cells(x, 4) = 4 Then session.findById("wnd[0]/usr/sub:SAPMM07R:0521/chkRESB-XLOEK[3,83]").Selected = True session.findById("wnd[0]/tbar[0]/btn[11]").press Cells(x, 3) = session.findById("wnd[0]/sbar").Text End If If Cells(x, 4) = 5 Then session.findById("wnd[0]/usr/sub:SAPMM07R:0521/chkRESB-XLOEK[4,83]").Selected = True session.findById("wnd[0]/tbar[0]/btn[11]").press Cells(x, 3) = session.findById("wnd[0]/sbar").Text End If If Cells(x, 4) = 6 Then session.findById("wnd[0]/usr/sub:SAPMM07R:0521/chkRESB-XLOEK[5,83]").Selected = True session.findById("wnd[0]/tbar[0]/btn[11]").press Cells(x, 3) = session.findById("wnd[0]/sbar").Text End If If Cells(x, 4) = 7 Then session.findById("wnd[0]/usr/sub:SAPMM07R:0521/chkRESB-XLOEK[6,83]").Selected = True session.findById("wnd[0]/tbar[0]/btn[11]").press Cells(x, 3) = session.findById("wnd[0]/sbar").Text End If If Cells(x, 4) = 8 Then session.findById("wnd[0]/usr/sub:SAPMM07R:0521/chkRESB-XLOEK[7,83]").Selected = True session.findById("wnd[0]/tbar[0]/btn[11]").press Cells(x, 3) = session.findById("wnd[0]/sbar").Text End If Next
This code is OK.
But i made the loop. because the code is very big:
For x = 4 To 5000 If Cells(x, 2) = "" Then Exit For session.findById("wnd[0]").maximize session.findById("wnd[0]/tbar[0]/okcd").Text = "/nmb22" session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/ctxtRM07M-RSNUM").Text = Cells(x, 2) session.findById("wnd[0]/usr/ctxtRM07M-RSNUM").caretPosition = 0 session.findById("wnd[0]").sendVKey 0 '-----------ITENS------------------------- For i = 1 To 15 If Cells(x, 4) = i Then session.findById("wnd[0]/usr/sub:SAPMM07R:0521/chkRESB-XLOEK[" & (i - 1) & ",83]").Selected = True 'marca a linha em aberto. session.findById("wnd[0]/tbar[0]/btn[11]").press 'salvar Cells(x, 3) = session.findById("wnd[0]/sbar").Text 'pega msg gerada End If Next Next
But the code with the loop is not OK. Whats the error?
Tank's