Copy data from Excel to SAP using VBA code

Cime14

New Member
Joined
Dec 19, 2017
Messages
30
Hi,

I am using below vba code to exctract data from SAP to excel.
In this case vba code insert parameters to SAP transaction code selection (e.g. 20070203) and execute/export report.
Is it possible to creat vba code which will copy parameters from excel and past it in t-code instead of now determined value 20070203?
For example from excel sheet cell in row 1, column A. Which part of code has to be updated and how?

Thank you for your help!!

VBA Code:
If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUISERVER")
   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]").resizeWorkingPane 270,33,false
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtSD_SAKNR-LOW").text = "20070203" - "VALUE TO BE COPIED FROM EXCEL"!
session.findById("wnd[0]/usr/ctxtSD_BUKRS-LOW").text = "AT06"
session.findById("wnd[0]/usr/ctxtSD_SAKNR-LOW").caretPosition = 8
session.findById("wnd[1]/usr/subSUBSCREEN:SAPLSPRI:0600/cmbPRIPAR_DYN-PRIMM").setFocus
session.findById("wnd[1]/usr/subSUBSCREEN:SAPLSPRI:0600/cmbPRIPAR_DYN-PRIMM").key = ""
session.findById("wnd[1]/tbar[0]/btn[13]").press
session.findById("wnd[1]/usr/btnSOFORT_PUSH").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/tbar[0]/btn[11]").press
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtBTCH2170-FROM_DATE").text = "01.01.2020"
session.findById("wnd[0]/usr/ctxtBTCH2170-TO_DATE").text = "31.12.2999"
Application.Wait (Now + TimeValue("0:00:10"))
session.findById("wnd[0]/usr/ctxtBTCH2170-TO_DATE").setFocus
session.findById("wnd[0]/usr/ctxtBTCH2170-TO_DATE").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/usr/lbl[136,10]").setFocus
session.findById("wnd[0]/usr/lbl[136,10]").caretPosition = 5
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/lbl[147,10]").setFocus
session.findById("wnd[0]/usr/lbl[147,10]").caretPosition = 3
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]").sendVKey 40
session.findById("wnd[0]/usr/chk[1,12]").selected = true
session.findById("wnd[0]/usr/chk[1,12]").setFocus
session.findById("wnd[0]").sendVKey 44
session.findById("wnd[0]/usr/chk[1,3]").selected = true
session.findById("wnd[0]/usr/lbl[21,3]").setFocus
session.findById("wnd[0]/usr/lbl[21,3]").caretPosition = 0
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").select
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").setFocus
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtDY_PATH").text = "C:\..."
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "TEST_AT06_2.xls"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 9
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[0]/btn[15]").press<br>
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,214,560
Messages
6,120,222
Members
448,951
Latest member
jennlynn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top