Hallo Leute,
ich stehe gerade vor einem Problem, hier schonmal der Code, wichtig ist das markierte am Ende:
Public Sub SAP()
    On Error GoTo Fehler
    Application.DisplayAlerts = False
    
    Dim SapGuiApp As Object
    Dim oConnection As Object
    Dim SAPSesi As Object
    
    If SapGuiApp Is Nothing Then
        Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
    End If
    
    If oConnection Is Nothing Then
        Set oConnection = SapGuiApp.OpenConnection(sapSystem, True)
    End If
    
    If SAPSesi Is Nothing Then
       Set SAPSesi = oConnection.Children(0)
    End If
    
    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
            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 Weiter
                .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
                
Weiter:
                '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[0]/tbar[0]/btn[11]").press
                Cells(i, 3).Value = "Ok"
[h]                .findById("wnd[1]/usr/btnSPOP-OPTION1").press[/h]
                'Range(Cells(i, 1), Cells(i, 2)).Interior.Color = 6
            End If
        Next
    End With
Beenden:
    Application.DisplayAlerts = True
    Set SAPSesi = Nothing
    Set oConnection = Nothing
    Set SapGuiApp = Nothing
    Exit Sub
    
Fehler:
    MsgBox Err.Description, vbCritical, "Fehler"
    GoTo Beenden
End Sub
Ab und zu wirft SAP eine Warnmeldung beim speichern, diese Meldung kann ich mit dem gelb markierten Befehl bestätigen. Wenn diese Meldung allerdings nicht kommt, stürzt alles ab.
Was nun? Errorhandling scheint hier nicht zu funktionieren. Kann ich irgendwie prüfen, ob wnd[1] existiert? oder gar der Button existiert?
Bitte helft mir, sonst darf ich heute noch drei Stunden manuell Daten ändern.
Danke & Grüße aus Regensburg!
                      Bearbeitet vom Benutzer
                       
vor 12 Jahre
 | 
Grund: Nicht angegeben