In the Display PO transaction in SAP the account assignment tab changes format. The first section of code captures the data in one format, the second will capture it in the alternate format. As the program is running when the frist section thros an error I need the program to disregard the error and pick up with the second section of code. If there is no error with the first section of code I need the program to disregard the second section. I have tried On Error Goto line1 (and inserted line1: below the first section but the second time through the loop it throws an error.
Cells(i, 21).Value = session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT12/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEACCTVI:0100/subSUB1:SAPLMEACCTVI:1100/txtMEACCT1100-ABLAD").Text
Cells(i, 21).Value = session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT12/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEACCTVI:0100/subSUB1:SAPLMEACCTVI:1000/tblSAPLMEACCTVIDYN_1000TC/txtMEACCT1000-ABLAD[11,0]").Text
full code below ***********************************************************************************************
update Macro
'
'Catch and redirect errors in case SAP GUI is not
'open or not accessible
On Error GoTo NotConnected
'Get the SAP GUI Scripting object
Set SapGuiAuto = GetObject("SAPGUI")
'Get the currently running SAP GUI
Set SAPApp = SapGuiAuto.GetScriptingEngine
'Get the first system that is currently connected
Set SAPCon = SAPApp.Children(0)
'Get the first session (window) on that connection
Set session = SAPCon.Children(0)
'Return to regular error handling
On Error GoTo 0
'Your code here
'...
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "ME23N"
session.findById("wnd[0]").sendVKey 0
Dim i As Integer
i = 2
Dim Data As Object
Dim x As Integer
Application.ScreenUpdating = False
' Set numrows = number of rows of data.
NumRows = Range("S2", Range("S2").End(xlDown)).Rows.Count
' Select cell a1.
Range("S2").Select
' Establish "For" loop to loop "numrows" number of times.
For x = 1 To NumRows
session.findById("wnd[0]/mbar/menu[0]/menu[0]").Select
session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-EBELN").Text = Application.ActiveCell
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]").maximize
Cells(i, 20).Value = session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-EEIND[9,0]").Text
Cells(i, 21).Value = session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT12/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEACCTVI:0100/subSUB1:SAPLMEACCTVI:1100/txtMEACCT1100-ABLAD").Text
Cells(i, 21).Value = session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT12/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEACCTVI:0100/subSUB1:SAPLMEACCTVI:1000/tblSAPLMEACCTVIDYN_1000TC/txtMEACCT1000-ABLAD[11,0]").Text
i = i + 1
'
' Selects cell down 1 row from active cell.
ActiveCell.Offset(1, 0).Select
Next
Application.ScreenUpdating = True
Set session = Nothing
'Exception handling in case SAP GUI is not
'open or not accessible
Exit Sub
NotConnected:
MsgBox "Please log into SAP first.", vbCritical
End Sub