Copier des fichiers à partir d'un fichier Excel

Bonjour , Bonne année 2020 à tous

je veux copier des fichiers d'une source à une destination d'une façon un peu particulière

J'ai un fichier Excel qui contient

Colonnes A : Nom Ficher

Colonnes B : Source Path du Fichier

Colonnes B : Desination Path du Fichier

Je veux une macro qui

Copie le Fichier de la colonne A

De la destination B

Vers la destination C

merci d'avance, et je suis là pour toute information complémentaire

Salut framxn,

à tester

Sub CopierFichier()
Dim fso As Object
Dim Derligne As Long
Dim i As Integer

Derligne = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To Derligne
Source = Range("B" & i).Value & "\" & Range("A" & i).Value
Destination = Range("C" & i).Value & "\"
Set fso = VBA.CreateObject("Scripting.FileSystemObject")

If Not fso.FolderExists(Destination) Then
    fso.CreateFolder Destination
End If
Call fso.CopyFile(Source, Destination)
Next i
End Sub

bonjour,

merci pour la réponse, ci-joint mon fichier, pouvez vous m'expliquer un peu plus vis à vis de mon fichier ?

10excel.xlsx (97.76 Ko)

Re,

si tout les fichiers sont des xlsx alors comme ca

Sub CopierFichier()
Dim fso As Object
Dim Derligne As Long
Dim i As Integer

Derligne = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To Derligne
Source = Range("B" & i).Value & Range("A" & i).Value & ".xlsx"
Destination = Range("C" & i).Value
Set fso = VBA.CreateObject("Scripting.FileSystemObject")

If Not fso.FolderExists(Destination) Then
    fso.CreateFolder Destination
End If
Call fso.CopyFile(Source, Destination)
Next i
End Sub

merci, mais les fichiers que je voudrais copier sont dans le fichier excel que je t'ai envoyé, ce sont dse fichiers .yaml

En gros j'ai deux Dossier

Dossier A qui a pleinsde sous dossier

Dossier B qui a pleins de sous dossier

je veux transférer les fichiers qui se trouve Dans A dans la nouvelle arborescence qui se trouve dans le dossier B en respectant le tableau excel

ah ok,

donc comme ca

Sub CopierFichier()
Dim fso As Object
Dim Derligne As Long
Dim i As Integer

Derligne = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To Derligne
Source = Range("B" & i).Value & Range("A" & i).Value
Destination = Range("C" & i).Value
Set fso = VBA.CreateObject("Scripting.FileSystemObject")

If Not fso.FolderExists(Left(Destination, Len(Destination) - 1)) Then
    fso.CreateFolder Destination
    Destination = Destination & "\"
End If

Call fso.CopyFile(Source, Destination)
Next i
End Sub

tu peux m'expliquer la ligne du strx stp ? car ça ne compile pas

Quel strx?

Excusez moi mais la solution ne marche pas :

je te donne un exemple :

Colonne A

Fichier1.yaml

Colonne B

C:\Users\X\Desktop\data\FGS\\paysafecard\

Colonne C :

C:\Users\X\Desktop\Portail API\B2BServices\paysafecard\

moi ce que je veux c'est Copier le fichier de la colonne A qui se trouve dans la colonne B, vers la destination dans la colonne C

Mais je vois pas pourquoi ca fonctionne pas chez toi

chez moi ca fonctionne trés bien!

Sub CopierFichier()
Dim fso As Object
Dim Derligne As Long
Dim i As Integer

Derligne = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To Derligne
Source = Range("B" & i).Value & Range("A" & i).Value
Destination = Range("C" & i).Value
Set fso = VBA.CreateObject("Scripting.FileSystemObject")

If Not fso.FolderExists(Left(Destination, Len(Destination) - 1)) Then
    fso.CreateFolder Destination
    Destination = Destination & "\"
End If

Call fso.CopyFile(Source, Destination)
Next i
End Sub

le problème est là :

If Not fso.FolderExists(Left(Destination, Len(Destination) - 1)) Then

fso.CreateFolder Destination

Destination = Destination & "\"

End If

il me dit argument ou appel de procédure incorrect

ben si les chemins de destinations existent enlève ce code

If Not fso.FolderExists(Left(Destination, Len(Destination) - 1)) Then

fso.CreateFolder Destination

Destination = Destination & "\"

End If

et essaie comme ca

Sub CopierFichier()
Dim fso As Object
Dim Derligne As Long
Dim i As Integer

Derligne = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To Derligne
Source = Range("B" & i).Value & Range("A" & i).Value
Destination = Range("C" & i).Value
Set fso = VBA.CreateObject("Scripting.FileSystemObject")

Call fso.CopyFile(Source, Destination)
Next i
End Sub

Est ce que Microsoft Script Runtime sous les références est activé chez toi?

lui

je l'ai essayé avec un dossier simple ça a marché, mais avec mon fichier ça ne marche pas je crois j'ai un problème avec mon tableau excel :/

je l'ai essayé avec un dossier simple ça a marché, mais avec mon fichier ça ne marche pas je crois j'ai un problème avec mon tableau excel :/

pffff

tu peux checker le fichier et me dire si il est conforme stp ?

4excel.xlsx (98.74 Ko)

Mais dans la feuille mapping, il y a des fichiers qui n'ont pas de destination!

Oui, effectivement, mais je les ai décoché de la liste au moment du lancement du batch

essaie comme ca

Sub CopierFichier()
Dim fso As Object
Dim Derligne As Long
Dim i As Integer

Derligne = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To Derligne
Source = Range("B" & i).Value & Range("A" & i).Value
Destination = Range("C" & i).Value

If Range("A" & i).Value<>"" And Source<>"" And Destination <> "" Then
Set fso = VBA.CreateObject("Scripting.FileSystemObject")

If Not fso.FolderExists(Left(Destination, Len(Destination) - 1)) Then
    fso.CreateFolder Destination
    Destination = Destination & "\"
End If

Call fso.CopyFile(Source, Destination)
End If
Next i

End Sub
Rechercher des sujets similaires à "copier fichiers partir fichier"