'-Begin-----------------------------------------------------------------

  '-Directives----------------------------------------------------------
    Option Explicit
    On Error Resume Next

  '-Global Variables----------------------------------------------------
    Dim SapGuiAuto, application, connection, session, QuitFlag

  '-Class cCheck--------------------------------------------------------
    Class cCheck

      '-Instance Variables----------------------------------------------
        Dim CmdField

      '-Method Exe------------------------------------------------------
        Public Sub Exe(ByVal Cmd)
          CmdField = Split(Cmd, """", -1, 1)
          session.findById(CmdField(1))
          ExecuteGlobal Cmd
        End Sub

      '-Method ErrCatch-------------------------------------------------
        Private Sub ErrCatch
          If Err.Number = 0 Then Exit Sub
          Select Case Err.Number
            Case 619
              If MsgBox("Run-time error " & Err.Number & _
                " occurred." & vbCrLf & Err.Description & vbCrLf & _
                "ID: " & CmdField(1) & vbCrLf & vbCrLf & "Abort?", _
                vbYesNo, "Error on " & Err.Source) = vbYes Then
                QuitFlag = True
              End If
            Case Else
              If MsgBox("Run-time error " & Err.Number & _
                " occurred." & vbCrLf & Err.Description & vbCrLf & _
                vbCrLf & "Abort?", vbYesNo, "Error on " & _
                Err.Source) = vbYes Then
                QuitFlag = True
              End If
          End Select
          Err.Clear
        End Sub

      '-Destructor------------------------------------------------------
        Private Sub Class_Terminate
          ErrCatch
        End Sub

    End Class

  '-Sub C---------------------------------------------------------------
    Sub C(ByVal Cmd)
      Dim Check
      If QuitFlag Then WScript.Quit()
      Set Check = New cCheck : Check.Exe Cmd : Set Check = Nothing
    End Sub

  '-Main----------------------------------------------------------------
    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

    C "session.findById(""wnd[0]/usr/txtRSYST-MANDT"").text = ""001"""
    '-This object doesn't exist-----------------------------------------
    C "session.findById(""wnd[0]/usr/txtRSYST-MAND"").text = ""001"""
    C "session.findById(""wnd[0]/usr/txtRSYST-BNAME"").text = ""bcuser"""
    C "session.findById(""wnd[0]/usr/pwdRSYST-BCODE"").text = ""minisap"""
    C "session.findById(""wnd[0]/usr/txtRSYST-LANGU"").text = ""EN"""
    C "session.findById(""wnd[0]/tbar[0]/btn[0]"").press"

'-End-------------------------------------------------------------------