Hello Team,
We use the Tcode: ZABCDV488002359 to get the inactive BOM 95 status. But the challenge here is I am not sure how to capture the icon. I need to find the red colored icon and enter the error msg for the particular BOM in the excel sheet.
Also I am unsure of how to locate the icon correctly, since in the below scenario the icon is present in the second table but sometime it appears in the first table or when click on Activate button an error popup appears, so not sure which way should I crack this code. Please could someone help me on how to get this sorted.
Sub SAPWork()
Dim SAPApplication As Variant
Lastrw = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To Lastrw
If Cells(i, 1) <> "" Then
Mat = Cells(i, 1).Value
Plnt = Cells(i, 2).Value
Useg = Cells(i, 3).Value
Alt = Cells(i, 4).Value
Dt = Format(Cells(i, 5).Value, "m/d/yy")
If Not IsObject(SAPApplication) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPApplication = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAPApplication.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 SAPApplication, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nZABCDV488002359"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtS_WERKS-LOW").Text = Plnt
session.findById("wnd[0]/usr/txtS_USAGE-LOW").Text = Useg
session.findById("wnd[0]/usr/ctxtS_MATNR-LOW").Text = Mat
session.findById("wnd[0]/usr/ctxtS_MATNR-LOW").SetFocus
session.findById("wnd[0]/usr/ctxtS_MATNR-LOW").caretPosition = 10
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/cntlZMMRBOMRTE_GRID/shellcont/shell").currentCellColumn = "MATNR"
session.findById("wnd[0]/usr/cntlZMMRBOMRTE_GRID/shellcont/shell").selectedRows = "0"
session.findById("wnd[0]/usr/cntlZMMRBOMRTE_GRID/shellcont/shell").doubleClickCurrentCell
session.findById("wnd[0]/usr/ctxtWA_WORK_BOM_HDR-MATNR").Text = Mat
session.findById("wnd[0]/usr/ctxtWA_WORK_BOM_HDR-STLAL").Text = Alt
session.findById("wnd[0]/usr/ctxtW_AENNR").Text = Dt
session.findById("wnd[0]/usr/ctxtW_AENNR").SetFocus
session.findById("wnd[0]/usr/ctxtW_AENNR").caretPosition = 6
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
BState = session.findById("wnd[0]/usr/subMAIN_SUB:ZMMMBOMS:9101/subWORK_AREA_SUB:ZMMMBOMS:9250/ctxtWA_WORK_BOM_HDR-STLST").Text
If BState = 95 Then
session.findById("wnd[0]/tbar[1]/btn[8]").press 'Deactivate or Activate
On Error Resume Next
'Br = session.findById("wnd[0]/shellcont/shell").selectedRows = "0"
'Br = session.findById("wnd[0]/shellcont/shell").currentCellColumn = "%_ICON"
On Error GoTo 0
If Br = "False" Then
session.findById("wnd[0]/shellcont").Close
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[1]/usr/btnBUTTON_1").press
Else: session.findById("wnd[0]/tbar[0]/btn[11]").press
End If
ElseIf BState = 91 Then
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/btn[11]").press
End If
End If
Next i
End Sub
