nburaq
Board Regular
- Joined
- Apr 2, 2021
- Messages
- 222
- Office Version
- 365
- 2019
- Platform
- Windows
Hi Gents,
I am trying to change a value in a sap table with the data provided in the excel list if the value in sap table is DEPT-MECH. Note that group and counter values are used to enter the table and Work Center is the data to be replaced if rows include DEPT-MECH. I know it requires a loop to check the [Row Number, Column number] and column number will always be constant like [2,1]. If anyone can help me I will be so glad. Thanks for your help and concern.
pS: I assume loop is required in session.findById("wnd[0]/usr/tblSAPLCPDITCTRL_3400/ctxtPLPOD-ARBPL[2,1]").text = COL3 line
I am trying to change a value in a sap table with the data provided in the excel list if the value in sap table is DEPT-MECH. Note that group and counter values are used to enter the table and Work Center is the data to be replaced if rows include DEPT-MECH. I know it requires a loop to check the [Row Number, Column number] and column number will always be constant like [2,1]. If anyone can help me I will be so glad. Thanks for your help and concern.
pS: I assume loop is required in session.findById("wnd[0]/usr/tblSAPLCPDITCTRL_3400/ctxtPLPOD-ARBPL[2,1]").text = COL3 line
VBA Code:
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, i
Dim x
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)) 'Group
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Counter
COL3= Trim(CStr(objSheet.Cells(i, 3).Value)) 'WorkCenter
Rem ADDED BY EXCEL ****************************************
session.findById("wnd[0]/tbar[0]/okcd").text = "/NIA06"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRC271-PLNNR").text = COL1 'Group
session.findById("wnd[0]/usr/txtRC271-PLNAL").text = COL2 'Counter
session.findById("wnd[0]/usr/txtRC271-PLNAL").setFocus
session.findById("wnd[0]/usr/txtRC271-PLNAL").caretPosition = 1
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/tblSAPLCPDITCTRL_3400/ctxtPLPOD-ARBPL[2,1]").text = COL3 'WorkCenter will be replaced with DEPT-ELEC if the workcenter is DEPT-MECH only
session.findById("wnd[0]/usr/tblSAPLCPDITCTRL_3400/ctxtPLPOD-ARBPL[2,1]").setFocus
session.findById("wnd[0]/usr/tblSAPLCPDITCTRL_3400/ctxtPLPOD-ARBPL[2,1]").caretPosition = 8
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[0]/btn[11]").press
objExcel.Cells(i, 4).Value = session.findById("wnd[0]/sbar").Text 'SystStat
Rem FINALIZATION CONTROL CHECK *****************************
aux=COL1 & " " & COL2
CreateObject("WScript.Shell").run("cmd /c @echo %date% %time% " & aux & " >> C:\Local\Script\CreationLog.txt")
Next
msgbox "Process Completed"