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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| Sub MB_52()
Dim SapGuiAuto As Object
Dim AppliSAP As Object
Dim Connection As Object
Dim Session As Object
Dim TmpSession As Object
Dim Chemin As String, Fichier As String
Dim Site, Entrepot, TypeArticle, MiseEnForme
'Modifier les 6 valeurs suivantes selon les besoins
Site = "Le numéro de site"
Entrepot = "Le numéro de l'entrepôt"
TypeArticle = "Le type d'article"
MiseEnForme = "/Le nom de la MEF"
Chemin = "C:\Temp"
Fichier = "MB52-" & Format(Date, "ddmmyyyy") & ".xls"
'Vérification si la fenêtre de connexion est ouverte
On Error Resume Next
Set SapGuiAuto = GetObject("SAPGUI")
If Err.Number <> 0 Then
MsgBox "Ouvrir une session SAP", vbExclamation, "Erreur de connexion"
Exit Sub
End If
If Not IsObject(SapGuiAuto) Then
Exit Sub
End If
On Error GoTo 0
Set AppliSAP = SapGuiAuto.GetScriptingEngine()
If Not IsObject(AppliSAP) Then
Exit Sub
End If
'Choisir la Session PRD non utilisée, si ouverte
For Each Connection In AppliSAP.Children
If Not Connection.DisabledByServer And Left(Connection.Description, 3) = "PRD" Then
For Each TmpSession In Connection.Children
If TmpSession.Busy = False Then
Set Session = TmpSession
GoTo FoundSession
End If
Next
End If
Next
FoundSession:
If Session Is Nothing Then
MsgBox "Ouvrir une session SAP-PRD et recommencer" & vbCrLf & _
"S'il y a une session ouverte, elle est probablement en cours d'exécution", vbExclamation, "Erreur de connexion"
Exit Sub
End If
'Démarre la transaction
Session.FindById("wnd[0]").maximize
Session.FindById("wnd[0]/tbar[0]/okcd").Text = "/nMB52"
Session.FindById("wnd[0]").SendVKey 0
'Inscrit les champs
Session.FindById("wnd[0]/usr/chkNOZERO").Selected = True
Session.FindById("wnd[0]/usr/chkNOVALUES").Selected = True
Session.FindById("wnd[0]/usr/chkNEGATIV").Selected = False
Session.FindById("wnd[0]/usr/ctxtWERKS-LOW").Text = Site
Session.FindById("wnd[0]/usr/ctxtLGORT-LOW").Text = Entrepot
Session.FindById("wnd[0]/usr/ctxtMATART-LOW").Text = TypeArticle
'Sélectionne les options
Session.FindById("wnd[0]/usr/chkNEGATIV").SetFocus
Session.FindById("wnd[0]").SendVKey 2
Session.FindById("wnd[0]/usr/chkXMCHB").Selected = False
Session.FindById("wnd[0]/usr/radPA_FLT").Select
Session.FindById("wnd[0]/usr/ctxtP_VARI").Text = "/STOCK VALO"
Session.FindById("wnd[0]/tbar[1]/btn[8]").Press
'Enregistrement "Texte avec tableurs"
Session.FindById("wnd[0]/tbar[1]/btn[45]").Press
Session.FindById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").Select
Session.FindById("wnd[1]/tbar[0]/btn[0]").Press
Session.FindById("wnd[1]/usr/ctxtDY_PATH").Text = Chemin
Session.FindById("wnd[1]/usr/ctxtDY_FILENAME").Text = Fichier 'inscrit le fichier
If Dir(Chemin & "\" & Fichier) <> "" Then Kill Chemin & "\" & Fichier 'supprime s'il existe déjà
Session.FindById("wnd[1]/tbar[0]/btn[0]").Press 'sauvegarde
MsgBox "Fichier sauvegardé", vbInformation, ""
End Sub |
Partager