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 88 89 90 91 92
| Sub Convert_File()
'Définition des variables
Dim chemin_acces_fichier As String
Dim xfile_source As Excel.Application
Dim donnees_H1 As Range
Dim donnees_H2 As Range
Dim EAN As String
Dim EAN_convert As String
Dim PRICE As Double
Dim PRICE_convert As String
Dim PRICE_2 As Double
Dim PRICE_convert_2 As String
Dim Price_3 As Double
Dim PRICE_CONVERT_3 As String
Dim Destinataire As String
Dim First_concurrent As String
Dim Second_concurrent As String
Dim Third_concurrent As String
Dim path_fichier
path_fichier = ThisWorkbook.Path & "\" & "Conversion.csv"
Dim deb_exe As Date, temps As Date, fin_exe As Date
deb_exe = Time
'Initialisation des variables
Set xfile_source = CreateObject("Excel.Application")
EAN = ""
EAN_convert = ""
PRICE = 0
PRICE_convert = 0
'Récupération du fichier à convertir
Application.FileDialog(msoFileDialogOpen).Show
chemin_acces_fichier = Application.FileDialog(msoFileDialogFilePicker).SelectedItems(1)
xfile_source.Workbooks.Open (chemin_acces_fichier)
xfile_source.Visible = False
'Zone de manipulation des donnee présentes dans le fichier
Set donnees_H1 = xfile_source.Range(xfile_source.Range("B3"), xfile_source.Range("E65000").End(xlUp))
'Ouverture du fichier de destination pour integration sur serveur METI
Open path_fichier For Output As #1
Destinataire = "000161"
First_concurrent = Range("C10")
Second_concurrent = Range("C11")
Third_concurrent = Range("C12")
'Parcourir la plage de données pour récupérer convertir les EAN et les prix
For i = 1 To donnees_H1.Rows.Count
EAN = donnees_H1.Cells(i, 1)
PRICE = donnees_H1.Cells(i, 4)
EAN_convert = String(13 - Len(Trim(EAN)), "0") & EAN
PRICE_convert = String(6 - Len(Trim(PRICE * 100)), "0") & PRICE * 100
Print #1, Destinataire & EAN_convert & First_concurrent & PRICE_convert
'Verification de la présence d'un prix dans la colonne contenant le rang tarifaire numéro 2
'Si il y a un prix alors je l'ajoute au fichier sinon je ne fais rien
'Recherche de la valeur par accès absolue
If IsEmpty(xfile_source.Cells(i + 2, 6)) = False Then
PRICE_2 = xfile_source.Cells(i + 2, 6)
PRICE_convert_2 = String(6 - Len(Trim(PRICE_2 * 100)), "0") & PRICE_2 * 100
Print #1, Destinataire & EAN_convert & Second_concurrent & PRICE_convert_2
End If
'Verification de la présence d'un prix dans la colonne contenant le rang tarifaire numéro 3
'Si il y a un prix alors je l'ajoute au fichier sinon je ne fais rien
'Recherche de la valeur par accès absolue
If IsEmpty(xfile_source.Cells(i + 2, 7)) = False Then
Price_3 = xfile_source.Cells(i + 2, 7)
PRICE_CONVERT_3 = String(6 - Len(Trim(Price_3 * 100)), "0") & Price_3 * 100
Print #1, Destinataire & EAN_convert & Third_concurrent & PRICE_CONVERT_3
End If
Next
Close #1
xfile_source.Application.DisplayAlerts = False
xfile_source.Application.Quit
fin_exe = Time
temps = fin_exe - deb_exe
MsgBox ("Fin d'éxecution du programme" & Chr(10) & "Delais d'éxecution : " & temps)
End Sub |
Partager