Sub MB51() Dim Appl, SapGuiAuto, Connection, Session, WScript Dim i, uCelula uCelula = Planilha3.Cells(Planilha3.UsedRange.Rows.Count, 1).Row For i = 2 To uCelula If Not IsObject(Appl) Then Set SapGuiAuto = GetObject("SAPGUI") Set Appl = SapGuiAuto.GetScriptingEngine End If If Not IsObject(Connection) Then Set Connection = Appl.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 Appl, "on" End If If Cells(i, "a") = "Dt.entr." Then Exit For End If 'session.findById("wnd[0]").maximize Session.findById("wnd[0]/tbar[0]/okcd").Text = "/nMB51" Session.findById("wnd[0]").sendVKey 0 Session.findById("wnd[0]/usr/ctxtWERKS-LOW").Text = "6800" Session.findById("wnd[0]/usr/ctxtLGORT-LOW").Text = "AM01" Session.findById("wnd[0]/usr/ctxtBWART-LOW").Text = "101" Session.findById("wnd[0]/usr/ctxtBWART-HIGH").Text = "103" Session.findById("wnd[0]/usr/ctxtBUDAT-LOW").Text = Cells(i, "a") Session.findById("wnd[0]/usr/radRFLAT_L").SetFocus Session.findById("wnd[0]/usr/radRFLAT_L").Select Session.findById("wnd[0]/tbar[1]/btn[8]").press Session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[2]").Select Session.findById("wnd[1]/tbar[0]/btn[0]").press Session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "C:\Users\rf.lima\SAP\GUI" Session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "mb.txt" Session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 6 Session.findById("wnd[1]/tbar[0]/btn[11]").press Session.findById("wnd[0]/tbar[0]/btn[3]").press Session.findById("wnd[0]/tbar[0]/btn[3]").press Next iPlan = ActiveWorkbook.Name Workbooks.OpenText Filename:="C:\Users\rf.lima\SAP\GUI\mb.txt", Origin:= _ 65000, StartRow:=4, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 9), _ Array(1, 1), Array(12, 9), Array(13, 1), Array(23, 9), Array(24, 1), Array(27, 9), Array(28 _ , 1), Array(40, 9), Array(41, 1), Array(49, 9), Array(50, 1), Array(60, 9), Array(61, 1), _ Array(101, 9), Array(102, 1), Array(112, 9), Array(113, 1), Array(116, 9), Array(117, 1), _ Array(121, 9), Array(122, 1), Array(126, 9), Array(127, 1), Array(147, 9), Array(148, 1), _ Array(152, 9), Array(153, 1), Array(163, 9), Array(164, 1), Array(185, 9)), _ TrailingMinusNumbers:=True Cells.Select Range("A4").Select X = Cells(Cells.Rows.Count, "a").End(xlUp).Row - 4 Range(Cells(3, 1), Cells(X, 16)).Select Selection.Copy Destination:=Workbooks(iPlan).Worksheets("Planilha3").Range("A4") Cells.Select Range("A4").Select ActiveWorkbook.Close SAVECHANGES:=False End Sub