1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
Dim SapGuiAuto As Object
Dim AppliSAP As Object 'SAPFEWSELib.GuiApplication
Dim Connection As Object 'SAPFEWSELib.GuiConnection
Dim Session As Object 'SAPFEWSELib.GuiSession
Dim Grille As Object 'SAPFEWSELib.GuiTableControl
On Error GoTo Erreur
Set SapGuiAuto = GetObject("SAPGUI")
If Not IsObject(SapGuiAuto) Then
Exit Sub
End If
Set AppliSAP = SapGuiAuto.GetScriptingEngine()
If Not IsObject(AppliSAP) Then
Exit Sub
End If
Set Connection = AppliSAP.Connections(0)
If Not IsObject(Connection) Then
Exit Sub
End If
Set Session = Connection.Sessions(0)
If Not IsObject(Session) Then
Exit Sub
End If
'Connexion à la transaction
Session.FindById("wnd[0]/tbar[0]/okcd").Text = "/nme23n"
Session.FindById("wnd[0]/tbar[0]/btn[0]").Press
Set Grille = Nothing
Set Session = Nothing
Set Connection = Nothing
Set AppliSAP = Nothing
Set SapGuiAuto = Nothing
Exit Sub
Erreur:
If Err.Number = -2147221020 Or Err.Number = 614 Then
MsgBox "Démarrer une session SAP", vbExclamation, "Erreur SAP"
Application.WindowState = xlMaximized
Exit Sub
ElseIf Err.Number = 619 Then
MsgBox Err.Description & vbCrLf & "S'il y a une session BW ouverte, la fermer avant de rouler la macro", vbInformation, "Erreur SAP"
ElseIf Err.Number = 613 Then
Resume Next
Else
MsgBox Err.Number & vbCrLf & Err.Description
Stop
Resume
End If
Stop
Resume |
Partager