Code:
Sub FullExecution2()
Set Connection = GetObject("SAPGUI").GetScriptingEngine.Children(0)
If Not IsObject(session) Then
Set SAPsession = Connection.Children(0)
End If
With SAPsession
.findById("wnd[0]").maximize
Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(, "Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
COL1 = objSheet.Cells(2, 2)
COL2 = objSheet.Cells(5, 2)
COL3 = objSheet.Cells(6, 2)
COL4 = objSheet.Cells(7, 2)
'Download SAP FBL5N
.findById("wnd[0]").maximize
.findById("wnd[0]/tbar[0]/okcd").Text = "COL4"
.findById("wnd[0]").sendVKey 0
.findById("wnd[0]/tbar[1]/btn[17]").press
.findById("wnd[1]/tbar[0]/btn[12]").press
.findById("wnd[0]/tbar[1]/btn[17]").press
.findById("wnd[1]/usr/txtV-LOW").Text = "sales rebate"
.findById("wnd[1]/usr/txtV-LOW").caretPosition = 12
.findById("wnd[1]/tbar[0]/btn[8]").press
.findById("wnd[0]/usr/ctxtDD_BUKRS-LOW").Text = COL1
.findById("wnd[0]/usr/ctxtSO_BUDAT-LOW").Text = COL2
.findById("wnd[0]/usr/ctxtSO_BUDAT-HIGH").Text = COL3
.findById("wnd[0]/usr/ctxtSO_BUDAT-HIGH").SetFocus
.findById("wnd[0]/usr/ctxtSO_BUDAT-HIGH").caretPosition = 10
.findById("wnd[0]/tbar[1]/btn[8]").press
On Error GoTo 100
200
.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").currentCellRow = -1
.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectColumn "HKONT"
.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").contextMenu
.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectContextMenuItem "&XXL"
.findById("wnd[1]/usr/radRB_OTHERS").Select
.findById("wnd[1]/usr/cmbG_LISTBOX").SetFocus
.findById("wnd[1]/usr/cmbG_LISTBOX").Key = "08"
.findById("wnd[1]/tbar[0]/btn[0]").press
.findById("wnd[1]/tbar[0]/btn[0]").press
.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[0,0]").Select
.findById("wnd[1]/tbar[0]/btn[0]").press
.findById("wnd[1]/tbar[0]/btn[0]").press
End With
MsgBox "Work Completed"
Exit Sub
100
With SAPsession
'Switch List
.findById("wnd[0]").maximize
.findById("wnd[0]/mbar/menu[5]/menu[8]").Select
Resume 200
Resume 300
300
'Switch List
.findById("wnd[0]").maximize
.findById("wnd[0]/mbar/menu[5]/menu[8]").Select
End With
End Sub