Skip to Content

Price update on PO level Excel-SAP

Jan 05 at 03:34 PM


avatar image


Totally new to Script and Macro. I started with it Friday last week.

I’m trying to create a script/macro in excel that will take PO number from column A put it in SAP /nme22n and then take the price from column B and update it and save.

I was also thinking of having same kind of status verification in column C saying price update is ok or not.

Each time I receive an error saying (Object required) on line: session.findById("wnd[0]/tbar[0]/okcd").Text = "/nme22n"

Anyone who can help with this script?

I'm using SAP 7.50 if that is of any importance.

Thank you!

Private Sub CommandButton1_Click()

If Not IsObject(SAPGuiApp) Then
Set SAPGuiAuto = GetObject("SAPGUI")
Set SAPGuiApp = SAPGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAPGuiApp.Children(0)
End If
If Not IsObject(SAP_Session) Then
Set SAP_Session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject SAP_Session, "on"
WScript.ConnectObject SAPGuiApp, "on"
End If

Set xclapp = CreateObject("Excel.Application")
Set xclwbk = xclapp.Workbooks.Open("c:\Users\qadimuj\Desktop\Price update Jabil.xlsx")
Set xclsht = xclwbk.Sheets("Sheet1")

For i = 2 To xclapp.ActiveCell.SpecialCells(11).Row
For j = 1 To xclapp.ActiveCell.SpecialCells(11).Column - 1
If j = 1 Then PO = xclsht.Cells(i, j).Value
If j = 2 Then Price = xclsht.Cells(i, j).Value

'Script recording from SAP

session.findById("wnd[0]/tbar[0]/okcd").Text = "/nme22n"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-EBELN").Text = "PO"
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0020/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-NETPR[10,0]").Text = "Price"
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0020/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-NETPR[10,0]").caretPosition = 14
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 11

'The rest of the VBScript.

If Err.Number <> 0 Then
'The Excel worksheet has e.g. 2 columns of data and an error column.

xclsht.Cells(i, 3).Value = "Here is an error."
xclsht.Cells(i, 3).Value = "O.K."
End If
On Error GoTo 0

End Sub

capture.png (7.1 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers