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
| Sub ImportNewTxt()
Dim datemvt As String
Dim prodnb As String
Close #1
Open ("D:\Projet EXCEL_VB_TXT\Test\text.wri") For Input As #1 '-------------------------------------------------> ouverture du fichier en lecture
While Not EOF(1) '----------------------------------------------------------------------------------------------> demarrage de la boucle pour lecture du fichier
lign$ = "" '------------------------------------------------------------------------------------------------> initialisation d une variable à ""
Line Input #1, lign$ '--------------------------------------------------------------------------------------> lire une ligne du fichier et passage à la ligne suivante (et affactation dans une variable chaine)
If InStr(1, lign$, "Message-Date :") <> 0 Then '--------------------------------------------------------> test sur la date
datemvt$ = Mid$(lign$, 25, 8) '---------------------------------------------------------------------> extraction de la date
MsgBox (Mid$(lign$, 25, 8))
date_new_format = Mid$(datemvt$, 1, 2) & "/" & Mid$(datemvt$, 4, 2) & "/20" & Mid$(datemvt$, 7, 2) '> changement du format d'import de la date
date_new_format_date = CDate(date_new_format)
Columns("B:B").Select '-----------------------------------------------------------------------------> formule pour selectionner la bonne ligne dans la colonne date en fonction de la date du fichier .txt
With Selection.Find(date_new_format_date).Activate
End With
ad_date = ActiveCell.Address
MsgBox (ad_date)
End If
If InStr(1, lign$, "Customer Article No") <> 0 Then '---------------------------------------------------> test POSITIF sur la presence de la chaine de caractère recherchee dans la ligne du fichier lu
prodnb$ = Mid$(lign$, 32, 10) '---------------------------------------------------------------------> extraction du produit
MsgBox (Mid$(lign$, 32, 10))
Rows("1:1").Select '--------------------------------------------------------------------------------> formule pour selectionner la bonne ligne dans la colonne date en fonction de la date du fichier .txt
With Selection.Find(Mid$(lign$, 33, 10)).Activate
End With
ad_prod = ActiveCell.Address
MsgBox (ad_prod)
End If
If InStr(1, lign$, "Movement direction") <> 0 Then '----------------------------------------------------> test sur le mouvement
lign$ = lign$ & vbCrLf '----------------------------------------------------------------------------> formule sauter 2 lignes
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
prodmvt$ = Mid$(lign$, 11, 3) '---------------------------------------------------------------------> extraction du mouvement
MsgBox (Mid$(lign$, 11, 3))
If prodmvt$ <> "Rec" And prodmvt$ <> "Bal" Then '---------------------------------------------------> verifier les 3 premiers caracteres
lign$ = lign$ & vbCrLf '------------------------------------------------------------------------> formule sauter 4 lignes
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
ret$ = Mid$(lign$, 11, 9) '---------------------------------------------------------------------> extraction sortie
MsgBox (Mid$(lign$, 11, 9))
'---> formule pour importer la quantite en sortie
lign$ = lign$ & vbCrLf '------------------------------------------------------------------------> formule sauter 4 lignes
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
ref_d_a$ = Mid$(lign$, 91, 10) '----------------------------------------------------------------> extraction reference
MsgBox (Mid$(lign$, 91, 10))
'---> formule pour importer Ref_d_a dans le tableau
Else
If prodmvt$ <> "Ret" And prodmvt$ <> "Bal" Then '---------------------------------------------------> verifier les 3 premiers caracteres
lign$ = lign$ & vbCrLf '------------------------------------------------------------------------> formule sauter 4 lignes
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
rec$ = Mid$(lign$, 11, 9) '---------------------------------------------------------------------> extraction entree
MsgBox (Mid$(lign$, 11, 9))
'---> formule pour importer la quantite en entree
lign$ = lign$ & vbCrLf '------------------------------------------------------------------------> formule sauter 4 lignes
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
lign$ = lign$ & vbCrLf
Line Input #1, lign$
ref_d_a$ = Mid$(lign$, 91, 10) '-----------------------------------------------------------------> extraction reference
MsgBox (Mid$(lign$, 91, 10))
'---> formule pour importer Ref_d_a dans le tableau
End If
End If
End If
Wend '-----------------------------------------------------------------------------------------------------------> fin boucle
Close #1 '-------------------------------------------------------------------------------------------------------> fermeture du fichier
End Sub |
Partager