Hi, I'm trying to make macro that works with SAP. I would like to use On Error function for two options of pop up windows that appear. If it's not possible to execute 'session.findById("wnd[1]/usr/btnSPOP-OPTION1").press' the program should run 'session.findById("wnd[1]/usr/btnSPOP-VAROPTION2").press' instead. Unfortunately the macro stops working and I get error on the 'session.findById("wnd[1]/usr/btnSPOP-VAROPTION2").press' field. Do you know what could be the issue?
VBA Code:
For i = 2 To lastRow
docNumber = ThisWorkbook.Sheets("Sheet1").Range("A" & i).Value
selectedCC = ThisWorkbook.Sheets("Sheet1").Range("B" & i).Value
fiscalYear = ThisWorkbook.Sheets("Sheet1").Range("C" & i).Value
reversalReason = ThisWorkbook.Sheets("Sheet1").Range("E" & i).Value
reversalDate = ThisWorkbook.Sheets("Sheet1").Range("F" & i).Value
reversalPeriod = ThisWorkbook.Sheets("Sheet1").Range("G" & i).Value
session.findById("wnd[0]/usr/txtRF05R-AUGBL").Text = docNumber
session.findById("wnd[0]/usr/ctxtRF05R-BUKRS").Text = selectedCC
session.findById("wnd[0]/usr/txtRF05R-GJAHR").Text = fiscalYear
session.findById("wnd[0]/usr/txtRF05R-GJAHR").SetFocus
session.findById("wnd[0]/usr/txtRF05R-GJAHR").caretPosition = 4
session.findById("wnd[0]/tbar[0]/btn[11]").press
On Error GoTo errHandler
session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
errHandler:
session.findById("wnd[1]/usr/btnSPOP-VAROPTION2").press
On Error GoTo -1
session.findById("wnd[1]/usr/ctxtRF05R-STGRD").Text = reversalReason
session.findById("wnd[1]/usr/ctxtRF05R-BUDAT").Text = reversalDate
session.findById("wnd[1]/usr/txtRF05R-MONAT").Text = reverselPeriod
session.findById("wnd[1]/usr/txtRF05R-MONAT").SetFocus
session.findById("wnd[1]/usr/txtRF05R-MONAT").caretPosition = 2
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
Next i
Last edited by a moderator: