I'm having a bit of an issue with regards to a small script i wrote to update purchase order vendor payment terms as well as advancement of the PO version after said payment term has been updated (post save).
Very strange error that i'm hitting... depending on what tabs i'm utilizing within a PO for entering data (Delivery/Invoice or Version), it seems that the onscreen GUI size is changing which then alters the background code for the script. I've highlighted the portions of the script below that are failing. The element seems to be jumping between 0010, 0013, 0018, and 0020. I've had no luck in making an integer replacement for those elements and incrementing through the 4 variables.
If anyone could provide a bit of VBA insight here i'd appreciate it.
Dim session
Function MODPO()
Dim Application
Dim material, plant As String
Dim xPO As String
Dim sbarmessage As String
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
InputRow = InputBox("Enter the Starting Row", "Starting Row", 3)
Row = CInt(InputRow)
xPO = Worksheets("MODPO").Cells(Row, 1)
While xPO <> ""
xPO = Worksheets("MODPO").Cells(Row, 1)
xPAYTERMS = Worksheets("MODPO").Cells(Row, 2)
session.findById("wnd[0]/tbar[0]/okcd").Text = "/NME22N"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-EBELN").Text = xPO
session.findById("wnd[1]").sendVKey 0
sbarmessage = session.findById("wnd[0]/sbar").Text
If InStr(sbarmessage, "does not exist") Then
GoTo ROWPLUS
End If
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT1").Select
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT1/ssubTABSTRIPCONTROL2SUB:SAPLMEGUI:1226/ctxtMEPO1226-ZTERM").Text = xPAYTERMS
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/btn[11]").press
If session.ActiveWindow.Name = "wnd[1]" Then
If session.findById("wnd[1]").Text Like "Save*" Then
session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press
GoTo MODVERSION
End If
End If
If session.ActiveWindow.Name = "wnd[1]" Then
If session.findById("wnd[1]").Text Like "Information*" Then
session.findById("wnd[1]").Close
GoTo ROWPLUS
End If
End If
MODVERSION:
session.findById("wnd[0]/tbar[1]/btn[7]").press
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT13").Select
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT13/ssubTABSTRIPCONTROL2SUB:SAPLMEDCMV:0100/cntlDCMGRIDCONTROL1/shellcont/shell").modifyCheckbox 0, "REVOK", True
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT13/ssubTABSTRIPCONTROL2SUB:SAPLMEDCMV:0100/cntlDCMGRIDCONTROL1/shellcont/shell").currentCellColumn = "REVOK"
session.findById("wnd[0]/tbar[0]/btn[11]").press
If session.ActiveWindow.Name = "wnd[1]" Then
If session.findById("wnd[1]").Text Like "Save*" Then
session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press
End If
End If
ROWPLUS:
Row = Row + 1
xPO = Worksheets("MODPO").Cells(Row, 1)
Worksheets("MODPO").Cells(Row, 1).Select
Wend
End Function