Skip to Content
author's profile photo Former Member
Former Member

Code for scrolling to next line item in item tab for delivery date change in PO using VBA or Vbs?

Hi there,

I am trying to scroll to next line item in PO using ME22N , using VBA (currently), but facing some coding problem. If any of you can help me in this regard?

I have data in excel like PO #, Purchasing line item #, Material #, PO Qty,Delivery date & Statistical date.

Purchasing line item # is something like 20, 30, 40, but sometimes it could be 21, 32, 45.

So thing is that, code should identify Purchasing Line item # according to data in excel, scroll to the line item with specific #, than identify particular material with reference to Qty, and than change the required date from excel.

for reference i am attaching a snapshot of line item & the code on which i am working.

My code:

Sub Update_Delivery_statDate()

Dim App, Connection, session As Object, currentrow As Integer

Set SapGuiAuto = GetObject("SAPGUI")

Set App = SapGuiAuto.GetScriptingEngine

Set Connection = App.Children(0)

Set session = Connection.Children(0)

If IsObject(WScript) Then

WScript.ConnectObject session, "on"

WScript.ConnectObject Application, "on"

End If

Dim objExcel

Dim objSheet, intRow, i, j

Set objExcel = GetObject(, "Excel.Application")

Set objSheet = objExcel.ActiveWorkbook.ActiveSheet

For i = 2 To objSheet.UsedRange.Rows.Count 'Assuming there is a header row


session.findById("wnd[0]/tbar[0]/okcd").Text = "/nme22n"

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

Do Until objSheet.Cells(i, 2).Value = ""

If objSheet.Cells(i, 2).Value <> "" Then

COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1

COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Column2

COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) 'Column3

COL4 = Trim(CStr(objSheet.Cells(i, 4).Value)) 'Column4

COL5 = Trim(CStr(objSheet.Cells(i, 5).Value)) 'Column5

COL6 = Trim(CStr(objSheet.Cells(i, 6).Value)) 'Column5

COL7 = Trim(CStr(objSheet.Cells(i, 7).Value)) 'Column5

COL8 = Trim(CStr(objSheet.Cells(i, 8).Value)) 'Column5

COL9 = Trim(CStr(objSheet.Cells(i, 9).Value)) 'Column5

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

session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-EBELN").Text = COL2

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






session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT5/ssubTABSTRIPCONTROL1SUB:SAPLMEGUI:1320/tblSAPLMEGUITC_1320/ctxtMEPO1320-EEIND[2,0]").Text = COL9

session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT5/ssubTABSTRIPCONTROL1SUB:SAPLMEGUI:1320/tblSAPLMEGUITC_1320/ctxtMEPO1320-SLFDT[5,0]").Text = COL9


session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT5/ssubTABSTRIPCONTROL1SUB:SAPLMEGUI:1320/tblSAPLMEGUITC_1320/ctxtMEPO1320-SLFDT[5,0]").caretPosition = 10

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





objSheet.Cells(i, 3).Value = "DONE"


On Error Resume Next

End If

i = i + 1


Set objSheet = Nothing

Set objExcel = Nothing

Set SapGuiAuto = Nothing

Exit For


MsgBox "Process Completed"

End Sub

Capture.JPG (208.5 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Apr 24, 2015 at 09:21 PM

    assuming your problem is locating the correct line item, I would loop through the item overview section, looking for the correct item nbr, then choose the item nbr to get the detail section to change to that item nbr.

    Here is an example of performing just those steps

    Sub ME22N_EditPOLineItemTest()

    DesiredItemNbr = "20"

    NewDeliveryDate = "09/01/2015"

    For x = 1 To 100

    'Compare Item Nbr in first displayed row of item overview section to desired item nbr

    If DesiredItemNbr = SAPSession.FindById("wnd[0]/usr/subSUB0:SAPLMEGUI:0015/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-EBELP[1,0]").Text Then

    FoundMatch = True

    'select the Item nbr field and press F2 to get the item detail section to change


    'This is the Choose PO Item (Press F2) step

    SAPSession.FindById("wnd[0]").SendVKey 2

    Exit For


    'scroll item section down down one more row (so we are always comparing to the top visible row)

    SAPSession.FindById("wnd[0]/usr/subSUB0:SAPLMEGUI:0015/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211").verticalScrollbar.position = x

    End If

    Next x

    'if we found the item nbr, then go to work in the item detail section

    If FoundMatch Then

    'edit dleivery date field

    SAPSession.FindById("wnd[0]/usr/subSUB0:SAPLMEGUI:0015/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT5/ssubTABSTRIPCONTROL1SUB:SAPLMEGUI:1320/tblSAPLMEGUITC_1320/ctxtMEPO1320-EEIND[2,0]").Text = NewDeliveryDate

    End If

    End Sub

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 24, 2015 at 11:23 AM


    As this can be tricky I suggest to use filter Option, then required item will be on first Position in above table. Then we just Need to press 'Choose PO item' button. Then you will be on Detail Tabs for PO item.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.