cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Macro to extract data from SAP by copying from excel and past the clipboard

0 Kudos
926

I have a an excel file contain a column of sales contracts (SC) and I extract the sales orders (SO) matches them from a table . every day I receive a new file with new (SC) numbers . I do that by copy the the whole column and past it.

lets assume that SC in column (A) in excel how can I make a macro to automate this step.

here is the script I recorded from SAP.

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

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").selectedNode = "F00006"

session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "F00006"

session.findById("wnd[0]/usr/ctxtGD-TAB").text = "vbfa"

session.findById("wnd[0]/usr/txtGD-MAX_LINES").text = ""

session.findById("wnd[0]/usr/txtGD-MAX_LINES").setFocus

session.findById("wnd[0]/usr/txtGD-MAX_LINES").caretPosition = 0

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/tbar[1]/btn[18]").press

session.findById("wnd[0]/usr/tblSAPLSE16NSELFIELDS_TC/chkGS_SELFIELDS-MARK[5,1]").selected = true

session.findById("wnd[0]/usr/tblSAPLSE16NSELFIELDS_TC/chkGS_SELFIELDS-MARK[5,3]").selected = true

session.findById("wnd[0]/usr/tblSAPLSE16NSELFIELDS_TC/btnPUSH[4,3]").setFocus

session.findById("wnd[0]/usr/tblSAPLSE16NSELFIELDS_TC/btnPUSH[4,3]").press

session.findById("wnd[1]/tbar[0]/btn[24]").press

session.findById("wnd[1]/tbar[0]/btn[8]").press

session.findById("wnd[0]/tbar[1]/btn[8]").press

session.findById("wnd[0]/usr/cntlRESULT_LIST/shellcont/shell").pressToolbarContextButton "&MB_EXPORT"

session.findById("wnd[0]/usr/cntlRESULT_LIST/shellcont/shell").selectContextMenuItem "&XXL"

session.findById("wnd[1]/tbar[0]/btn[0]").press

session.findById("wnd[1]/usr/ctxtDY_PATH").text = "C:\Users\moazzam\Desktop"

session.findById("wnd[1]/usr/ctxtDY_PATH").setFocus

session.findById("wnd[1]/usr/ctxtDY_PATH").caretPosition = 24

session.findById("wnd[1]/tbar[0]/btn[0]").press

Accepted Solutions (0)

Answers (0)