Pesquisando na internet, cheguei na macro abaixo, mas está dando erro.
Sub Teste()
If Not IsObject(Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = Application.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 Application, "on"
End If
session.findById("wnd[0]").maximize
Rem ADDED BY EXCEL **********************************
Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(, ”Excel.Application”)
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
For i = 2 To objSheet.UsedRange.Rows.Count
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) ‘Column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) ‘Column2
Rem ADDED BY EXCEL **********************************
session.findById("wnd[0]/tbar[0]/okcd").Text = "CO09"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtCAUFVD-MATNR").Text = "column 2"
session.findById("wnd[0]/usr/ctxtCAUFVD-WERKS").Text = "column 1"
session.findById("wnd[0]/usr/ctxtCAUFVD-WERKS").SetFocus
session.findById("wnd[0]/usr/ctxtCAUFVD-WERKS").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/tblSAPLATP4CTR_400/txtMDEZ-MNG04[5,0]").SetFocus
session.findById("wnd[0]/usr/tblSAPLATP4CTR_400/txtMDEZ-MNG04[5,0]").caretPosition = 17
ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range("column 3")
End Sub
Postado : 09/11/2017 5:45 am