I would like to use For Each Loop for SAP transaction, but my list of orders contain variables that are non-existent in the transaction, thus bringing an error.
How do I fix this For Each Loop so that it completely ignores the error and just moves to the next item on the list?
The code doesn't accept my "Next" command after If.
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
'Variables
Dim order(2)
order(0)="xxx"
order(1)="yyy"
order(2)="zzz"
For Each x In order
On Error Resume Next
If err.number <> 0 Then
Next
Else
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/ctxtRC29L-MATNR").text = x
session.findById("wnd[0]/usr/ctxtRC29L-MATNR").caretPosition = 8
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[45]").press
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").select
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").setFocus
session.findById("wnd[1]/tbar[0]/btn[0]").press
'Path
session.findById("wnd[1]/usr/ctxtDY_PATH").text = "C:\Users\blabla"
'Order name
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = x + ".xls"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 12
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press
End If
On Error Goto 0
Next
Thanks to anyone interested!