cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Error Handling in VBA with SAPSession

Former Member
0 Kudos

Hello guys,

this i my code, important is only the end, i marked it:

    With SAPSesi

        .findById("wnd[0]/usr/txtRSYST-MANDT").Text = sapClient

        .findById("wnd[0]/usr/txtRSYST-BNAME").Text = SAPForm.BoxUser.Text

        .findById("wnd[0]/usr/pwdRSYST-BCODE").Text = SAPForm.BoxPass.Text

        .findById("wnd[0]/usr/txtRSYST-LANGU").Text = "DE"

        .findById("wnd[0]").sendVKey 0

       

        '----------------------------------------------------------------

        'SAP SKRIPT

        '----------------------------------------------------------------

        'CO02 ausführen

        .findById("wnd[0]/tbar[0]/okcd").Text = "CO02"

        .findById("wnd[0]").sendVKey 0

       

        'Daten eingeben & ausführen

        For i = 2 To Sheets(1).UsedRange.Rows.Count

            'On Error GoTo Fehler2

            If Cells(i, 3).Value = "" Then

                'Auftrag eingeben

                .findById("wnd[0]/usr/ctxtCAUFVD-AUFNR").Text = Cells(i, 1).Value

                .findById("wnd[0]").sendVKey 0

               

                'String suchen

                On Error GoTo Weiter1

                .findById("wnd[0]/mbar/menu[1]/menu[1]").Select

                .findById("wnd[1]/usr/txtRSYSF-STRING").Text = Cells(i, 2).Value

                .findById("wnd[1]/usr/txtRSYSF-STRING").caretPosition = 10

                .findById("wnd[1]").sendVKey 0

               

                'Gesuchten Auftrag auflisten

                .findById("wnd[2]/usr/lbl[16,2]").SetFocus

                .findById("wnd[2]/usr/lbl[16,2]").caretPosition = 7

                .findById("wnd[2]").sendVKey 2

                .findById("wnd[0]/tbar[1]/btn[18]").press

               

Weiter1:

                'Datum ändern

                On Error Resume Next

                .findById("wnd[0]/usr/tabsTABSTRIP_0115/tabpKOZE/ssubSUBSCR_0115:SAPLCOKO1:0120/ctxtCAUFVD-GLTRP").Text = Range("E1").Value

                .findById("wnd[0]/usr/tabsTABSTRIP_0115/tabpKOZE/ssubSUBSCR_0115:SAPLCOKO1:0120/ctxtCAUFVD-GLTRP").SetFocus

                .findById("wnd[0]/usr/tabsTABSTRIP_0115/tabpKOZE/ssubSUBSCR_0115:SAPLCOKO1:0120/ctxtCAUFVD-GLTRP").caretPosition = 10

                .findById("wnd[0]").sendVKey 0

                .findById("wnd[0]").sendVKey 0

                .findById("wnd[0]").sendVKey 0

                .findById("wnd[0]").sendVKey 0

               

                'Speichern

                .findById("wnd[0]").sendVKey 12

                .findById("wnd[1]/usr/btnSPOP-OPTION1").press

                Cells(i, 3).Value = "Ok"

            End If

        Next

    End With

Problem is, if the Message does not appear, the debugger throws an exception. How can i check, if the message shows or not?

Please help me or i have to make a lot of hours of manual work today

Accepted Solutions (1)

Accepted Solutions (1)

script_man
Active Contributor
0 Kudos

Hi Maximilian,

as already indicated, the construction of the solution could be as follows:

'Speichern

'.findById("wnd[0]").sendVKey 12 'deaktiviert

on error resume next

.findById("wnd[0]/tbar[0]/btn[11]").press

.findById("wnd[1]/usr/btnSPOP-OPTION1").press

on error goto 0

Cells(i, 3).Value = "Ok"

'usw.

Regards,

ScriptMan

Answers (0)