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
| Sub HK()
Dim application_SAP, connection, session, application_Excel As Object
If Not IsObject(application_SAP) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application_SAP = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application_SAP.Children(0)
End If
Set session = connection.Children(0)
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application_SAP, "on"
End If
Dim shA As Worksheet 'Feuille A
Dim wB As Workbook 'Classeur B
Dim i As Integer
i = Workbooks("Extraction Nomenclature.xlsm").Sheets("Source").Range("C1").Value
ligne = 2
On Error Resume Next
While Sheets("Source").Cells(ligne, 1) <> ""
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/NCS12"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRC29L-MATNR").Text = Sheets("Source").Cells(ligne, 1)
session.findById("wnd[0]/usr/ctxtRC29L-WERKS").Text = "XXXX"
session.findById("wnd[0]/usr/ctxtRC29L-CAPID").Text = "BEST"
session.findById("wnd[0]/usr/ctxtRC29L-CAPID").SetFocus
session.findById("wnd[0]/usr/ctxtRC29L-CAPID").caretPosition = 4
session.findById("wnd[0]/tbar[1]/btn[8]").press
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]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").SetFocus
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "C:\Users\XXXXXXX\Desktop\"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "EXPORT.XLS"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 10
session.findById("wnd[1]/tbar[0]/btn[11]").press
Workbooks("Extraction Nomenclature.xlsm").Activate
Sheets("Source").Cells(ligne, 1).Select
Selection.Copy
Sheets("Nomenclature").Select
Cells(i + 2, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.DisplayAlerts = False
Set wB = Workbooks.Open(Filename:="C:\Users\XXXXX\Desktop\EXPORT.XLS")
Sheets("sheet1").Select
Rows("1:9").Select
Selection.Delete Shift:=xlUp
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Cells.Select
Cells.EntireColumn.AutoFit
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
Rows("2:2").Select
Selection.Delete Shift:=xlUp
Range("A2:R250").Copy
wB.Close False ' ferme sans sauve
Set wB = Nothing
Workbooks("Extraction Nomenclature.xlsm").Activate
Sheets("Nomenclature").Select
Cells(i + 2, 1).Select
ActiveSheet.PasteSpecial Format:="Texte Unicode", Link:=False, _
DisplayAsIcon:=False, NoHTMLFormatting:=True
Sheets("Source").Cells(ligne, 2).Value = "OK"
ligne = ligne + 1
Wend
End Sub |
Partager