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
|
Function CopyfichtextA()
'PART A
' recherche si il existe un fichier "*-A-*.csv" dans le Rep "TRANSFO"; si oui:
' copie le contenu du fichier "*-A-*.csv" dans le fichier "xx.csv"
Dim sourcefile, DestinationFile
Set fs = Application.FileSearch
With fs
.LookIn = "C:\MAGEA400M\TRANSFO"
.Filename = "*-A-*.csv"
If .Execute > 0 Then
' MsgBox "Il y a " & .FoundFiles.Count & _
" fichier(s)."
i = 1 ' MODIFICATION DE LA BOUCLE SUR "FOR" pour prendre une seul fichier à la fois
' For i = 1 To .FoundFiles.Count
'MsgBox .FoundFiles(i)
sourcefile = .FoundFiles(i) ' Définit le nom du fichier source.
MsgBox .FoundFiles(i)
DestinationFile = "C:\MAGEA400M\TRANSFO\xx.csv" ' Définit le nom du fichier cible.
FileCopy sourcefile, DestinationFile ' Copie le fichier source dans le fichier cible.
If Mid(sourcefile, 34, 3) = "A-1" Then
MkDir "C:\MAGEA400M\ARCHIVES PARTS\1- PARTS\" & Mid(sourcefile, 21, 12)
Destinationfile2 = "C:\MAGEA400M\ARCHIVES PARTS\1- PARTS" & Mid(sourcefile, 21, 12) & Mid(sourcefile, 21)
FileCopy sourcefile, Destinationfile2
Else
Destinationfile2 = "C:\MAGEA400M\ARCHIVES PARTS\1- PARTS" & Mid(sourcefile, 21, 12) & Mid(sourcefile, 21)
FileCopy sourcefile, Destinationfile2
End If
MsgBox "File imported and transfered in history folder"
Kill sourcefile
'INSERER L'IMPORTATION A EFFECTUER ICI
' Next i
Else
MsgBox "Il n'y a pas de fichier."
End If
End With
End Function |
Partager