Bonjour,

Pour piloter SAP depuis VBA, j'ulise un script de connexion de ce type :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
On Error Resume Next
 
'Librairies ajoutées:
'Window script Host Object model
'Sap Remote Function call Control
'SAP GUI scripting API
 
Application.DisplayAlerts = False
 
If Not IsObject(SAP_applic) Then
    Set SapGuiAuto = GetObject("SAPGUI")
    Set SAP_applic = SapGuiAuto.GetScriptingEngine
End If
 
 
er = Err.Number
On Error GoTo 0
 
If er <> 0 Then
  er = 0
  On Error Resume Next
 
  Call Shell("C:\Program Files\SAP\FrontEnd\SAPGUI\saplogon.exe", vbMinimizedFocus)
  Call Shell("C:\Program Files\SAP\FrontEnd\SAPgui\saplogon.exe", vbMinimizedFocus)
  On Error GoTo 0
 
  er = 0
  On Error Resume Next
  If Not IsObject(SAP_applic) Then
    Set SapGuiAuto = GetObject("SAPGUI") 'Setting
    Set SAP_applic = SapGuiAuto.GetScriptingEngine
  End If
 
  er = Err.Number
  On Error GoTo 0
 
  If er <> 0 Then
    tmp = MsgBox("SAP Logon not installed on your system" & vbCrLf & _
      "Please install it using eSupport!", vbInformation)
    End
  End If
End If
 
Set Connection = SAP_applic.OpenConnection("0.1 - R/3 Production [SBP_LOGON]")
 
 
If Connection.Children.Count < 1 Then
Exit Sub
Else
Set session = Connection.Children(0)
End If
 
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "user"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "mdp"
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
session.findById("wnd[0]").sendVKey 0
Celui-ci ouvre une nouvelle connection avec utilisation du login et paswword.

Les utilisateur de mon programme excel, sont déjà connecté dans SAP. Pourriez-vous me transmettre un bout de code qui permet d'afficher la session déjà ouverte ?

J'arrive à éxécuter un vbs mais celui-ci m'oblige à utiliser un temps de pause VBA non régulier pour certaines transactions :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
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
 
session.findById("wnd[0]").maximize
...
merci pour votre aide,

Damien