Good day. I am very new to SAP Scripting and VBA and built the code below with the help of recording my interactions in SAP as well as searching the web. I am trying to schedule adhoc job runs from a list in Excel in SAP system using VBA, but I get errors for jobs that are not found in SM37, error happens at this line in code below:
session.findById("wnd[0]/tbar[1]/btn[8]").press
Finally got the skip to the next iteration working, unfortunately, 2nd error throws the same error message 619 and is not getting skipped forward to the next loop. What seems to be the problem with my code?
Code:
For i = 2 To objSheet.UsedRange.Rows.Count
If Trim(CStr(objSheet.Cells(i, 1).Value)) = "" Then
Exit For
End If
On Error GoTo Handler:
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nsm37"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/chkBTCH2170-PRELIM").Selected = False
session.findById("wnd[0]/usr/chkBTCH2170-READY").Selected = False
session.findById("wnd[0]/usr/chkBTCH2170-RUNNING").Selected = False
session.findById("wnd[0]/usr/chkBTCH2170-FINISHED").Selected = False
session.findById("wnd[0]/usr/chkBTCH2170-ABORTED").Selected = False
session.findById("wnd[0]/usr/txtBTCH2170-JOBNAME").Text = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Original Job Name - 1 is column A, 2 is column B and so on
session.findById("wnd[0]/usr/txtBTCH2170-USERNAME").Text = "*"
session.findById("wnd[0]/usr/ctxtBTCH2170-FROM_DATE").Text = ""
session.findById("wnd[0]/usr/ctxtBTCH2170-TO_DATE").Text = ""
session.findById("wnd[0]").sendVKey 0
objSheet.Cells(i, 3).Value = "Not Found"
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/lbl[4,12]").SetFocus
session.findById("wnd[0]/usr/lbl[4,12]").caretPosition = 0
session.findById("wnd[0]").sendVKey 30
session.findById("wnd[1]/usr/txtBTCH1180-JOBNAME").Text = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Name of the Adhoc Job
session.findById("wnd[1]/usr/txtBTCH1180-JOBNAME").caretPosition = 31
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]/usr/chkBTCH2170-PRELIM").Selected = True
session.findById("wnd[0]/usr/txtBTCH2170-JOBNAME").Text = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Name of the Adhoc Job
session.findById("wnd[0]/usr/chkBTCH2170-PRELIM").SetFocus
session.findById("wnd[0]/tbar[1]/btn[8]").press
objSheet.Cells(i, 3).Value = "AdHoc Released"
Handler:
On Error GoTo 0
Next