Note: The other languages of the website are Google-translated. Back to English
Se connecter  \/ 
x
or
x
INSCRIPTION  \/ 
x

or

Comment copier ou déplacer des fichiers d'un dossier à un autre en fonction d'une liste dans Excel? 

Si vous avez une liste de noms de fichiers dans une colonne d'une feuille de calcul et que les fichiers se trouvent dans un dossier de votre ordinateur. Mais, maintenant, vous devez déplacer ou copier ces fichiers dont les noms sont répertoriés dans la feuille de calcul de leur dossier d'origine vers un autre, comme illustré ci-dessous. Comment pourriez-vous terminer cette tâche aussi rapidement que possible dans Excel?

Copiez ou déplacez des fichiers d'un dossier à un autre en fonction d'une liste dans Excel avec le code VBA


Copiez ou déplacez des fichiers d'un dossier à un autre en fonction d'une liste dans Excel avec le code VBA

Pour déplacer les fichiers d'un dossier à un autre en fonction d'une liste de noms de fichiers, le code VBA suivant peut vous rendre service, procédez comme suit:

1. Maintenez le Alt + F11 clés dans Excel, et il ouvre le Microsoft Visual Basic pour applications fenêtre.

2. Cliquez insérer > Moduleet collez le code VBA suivant dans la fenêtre Module.

Code VBA: déplacer des fichiers d'un dossier à un autre en fonction d'une liste dans Excel

Sub movefiles()
'Updateby Extendoffice
    Dim xRg As Range, xCell As Range
    Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog
    Dim xSPathStr As Variant, xDPathStr As Variant
    Dim xVal As String
    On Error Resume Next
    Set xRg = Application.InputBox("Please select the file names:", "KuTools For Excel", ActiveWindow.RangeSelection.Address, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
    xSFileDlg.Title = " Please select the original folder:"
    If xSFileDlg.Show <> -1 Then Exit Sub
    xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\"
    Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
    xDFileDlg.Title = " Please select the destination folder:"
    If xDFileDlg.Show <> -1 Then Exit Sub
    xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\"
    For Each xCell In xRg
        xVal = xCell.Value
        If TypeName(xVal) = "String" And xVal <> "" Then
            FileCopy xSPathStr & xVal, xDPathStr & xVal
            Kill xSPathStr & xVal
        End If
    Next
End Sub

3. Et puis appuyez sur F5 clé pour exécuter ce code, et une boîte de dialogue apparaîtra pour vous rappeler de sélectionner les cellules qui contiennent les noms de fichiers, voir capture d'écran:

4. Puis clique OK bouton, et dans la fenêtre qui apparaît, sélectionnez le dossier contenant les fichiers que vous souhaitez déplacer, voir capture d'écran:

5. Et puis cliquez OK, continuez à sélectionner le dossier de destination où vous souhaitez localiser les fichiers dans une autre fenêtre pop-out, voir capture d'écran:

6. Enfin, cliquez OK pour fermer la fenêtre, et maintenant, les fichiers ont été déplacés dans un autre dossier que vous avez spécifié en fonction des noms de fichiers dans la liste des feuilles de calcul, voir capture d'écran:

Notes: Si vous souhaitez simplement copier les fichiers dans un autre dossier, mais conserver les fichiers d'origine, veuillez appliquer le code VBA ci-dessous:

Code VBA: copier des fichiers d'un dossier à un autre en fonction d'une liste dans Excel

Sub copyfiles()
'Updateby Extendoffice
    Dim xRg As Range, xCell As Range
    Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog
    Dim xSPathStr As Variant, xDPathStr As Variant
    Dim xVal As String
    On Error Resume Next
    Set xRg = Application.InputBox("Please select the file names:", "KuTools For Excel", ActiveWindow.RangeSelection.Address, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
    xSFileDlg.Title = "Please select the original folder:"
    If xSFileDlg.Show <> -1 Then Exit Sub
    xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\"
    Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
    xDFileDlg.Title = "Please select the destination folder:"
    If xDFileDlg.Show <> -1 Then Exit Sub
    xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\"
    For Each xCell In xRg
        xVal = xCell.Value
        If TypeName(xVal) = "String" And xVal <> "" Then
            FileCopy xSPathStr & xVal, xDPathStr & xVal
        End If
    Next
End Sub

Les meilleurs outils de productivité de bureau

Kutools for Excel résout la plupart de vos problèmes et augmente votre productivité de 80%

  • Réutilisation: Insérer rapidement formules complexes, graphiques et tout ce que vous avez utilisé auparavant; Crypter les cellules avec mot de passe; Créer une liste de diffusion et envoyer des e-mails ...
  • Barre Super Formula (modifiez facilement plusieurs lignes de texte et de formule); Disposition de lecture (lire et modifier facilement un grand nombre de cellules); Coller dans la plage filtrée...
  • Fusionner les cellules / lignes / colonnes sans perdre de données; Contenu des cellules divisées; Combiner des lignes / colonnes en double... Empêcher les cellules en double; Comparer les gammes...
  • Sélectionnez Dupliquer ou Unique Lignes; Sélectionnez les lignes vides (toutes les cellules sont vides); Super Find et Fuzzy Find dans de nombreux classeurs; Sélection aléatoire ...
  • Copie exacte Plusieurs cellules sans changer la référence de formule; Créer automatiquement des références à plusieurs feuilles; Insérer des puces, Cases à cocher et plus encore ...
  • Extrait du texte, Ajouter du texte, Supprimer par position, Supprimer l'espace; Créer et imprimer des sous-totaux de pagination; Conversion entre le contenu et les commentaires des cellules...
  • Super filtre (enregistrer et appliquer des schémas de filtrage à d'autres feuilles); Tri avancé par mois / semaine / jour, fréquence et plus; Filtre spécial par gras, italique ...
  • Combiner des classeurs et des feuilles de travail; Fusionner les tableaux en fonction des colonnes clés; Diviser les données en plusieurs feuilles; Conversion par lots xls, xlsx et PDF...
  • Plus de 300 fonctionnalités puissantes. Prend en charge Office / Excel 2007-2019 et 365. Prend en charge toutes les langues. Déploiement facile dans votre entreprise ou organisation. Essai gratuit de 30 jours. Garantie de remboursement de 60 jours.
onglet kte 201905

Office Tab apporte une interface à onglets à Office et simplifie considérablement votre travail

  • Activer l'édition et la lecture par onglets dans Word, Excel, PowerPoint, Publisher, Access, Visio et Project.
  • Ouvrez et créez plusieurs documents dans de nouveaux onglets de la même fenêtre, plutôt que dans de nouvelles fenêtres.
  • Augmente votre productivité de 50% et réduit des centaines de clics de souris chaque jour!
bas de cabine
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    MarcW · 25 days ago
    Is pressing "F5" supposed to take me back to the last active sheet when the VBA module runs? I am running Excel 2019 (almost equiv. to Excel 365). Is there something else I should do instead to run it?
  • To post as a guest, your comment is unpublished.
    Evelyne · 1 months ago
    Everything was OK for me (800 files to copy from a folder containing 10000 files).
    Many thanks.
  • To post as a guest, your comment is unpublished.
    marc_vie · 2 months ago
    Excellent macro.
    How can this be modified for my need case as below. I have zero experience in VBA.
    The source folders (3 – zmf, vek, num) and destination folders (4 – jack, james, john, jane) names and paths are constant.
    Source folders (3)
    \\192.168.xx.x\ma\zmf\ (files here – 123.wav, 456.wav, etc)
    \\192.168.xx.x\ma\vek\ (files here – abc.wav, etc)
    \\192.168.xx.x\ma\num\ (files here – ghi.wav, etc)
    Destination folders (4)
    \\192.168.xx.xx\ba\jack\
    \\192.168.xx.xx\ba\james\
    \\192.168.xx.xx\ba\john\
    \\192.168.xx.xx\ba\jane\
    In Excel sheet, in Column A I have the list of files (will change on a daily basis) which have to be COPIED (not moved) to the folder in Column B (the folder in which the files are contained (zmf, vek, num) also have to be copied.
    For example, 123.wav has to be copied to the folder “jack” such as \\192.168.xx.xx\ba\jack\zmf\123.wav
        abc.wav has to be copied to the folder “jane” such as \\192.168.xx.xx\ba\jane\vek\abc.wav
        ghi.wav also has to be copied to the folder “jack” such as \\192.168.xx.xx\ba\jack\num\ghi.wav
        
    Column A    Column B
    Files in Source folders    Destination folders (constant)
    123.wav    jack
    456.wav    james
    789.wav    john
    abc.wav    jane
    def.wav    james
    ghi.wav    jack

    Can anyone help with modifying this macro please?
  • To post as a guest, your comment is unpublished.
    G · 8 months ago
    I have a list of 10000 files that need to be moved but the above code stops after taking source file location. Kindly let me know if I need to change anything in the code.
  • To post as a guest, your comment is unpublished.
    enesa20 · 10 months ago
    Hello,
    I need some additional help with the VBA code.

    My excel list has names like this:

    ABCDEF

    The .jpg files Im trying to match are:

    ABCDEF_1, ABCDEF_2, ABCDEF_3 ....

    Some names on the list has more than 1 .jpg files and I want ALL of those files to be copied. Could anybody please modify the code accordingly?,,

    Thank you very much!!
  • To post as a guest, your comment is unpublished.
    Walter · 10 months ago
    Hallo,
    what must i change when i always want to search pdf and jpg files and then copy thes in only one destination folder?
  • To post as a guest, your comment is unpublished.
    Joelle · 11 months ago
    Thank you! you are a life saver!
  • To post as a guest, your comment is unpublished.
    Puneet Goel · 1 years ago
    Thanks a lot.....It really worked very well and solved the issue completely
  • To post as a guest, your comment is unpublished.
    Steve · 1 years ago
    Can anyone help to adapt the code to search specific files in folder and subfolers then copy it to destination?
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, Steve,
      To copy the files from one folder including the subfolders to another folder based on the list in sheet, please apply the following code.
      Please try, hope it can help you!
      Sub Copyfiles() 'Updateby Extendoffice Dim xRg As Range, xCell As Range Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog Dim xSPathStr As Variant, xDPathStr As Variant Dim xVal As String Dim fso As Object, folder1 As Object Set xRg = Application.InputBox("Please select the file names:", "KuTools For Excel", ActiveWindow.RangeSelection.Address, , , , , 8) If xRg Is Nothing Then Exit Sub Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker) xSFileDlg.Title = " Please select the original folder:" If xSFileDlg.Show <> -1 Then Exit Sub xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\" Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker) xDFileDlg.Title = " Please select the destination folder:" If xDFileDlg.Show <> -1 Then Exit Sub xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\" Call sCopyFiles(xRg, xSPathStr, xDPathStr) End Sub Sub sCopyFiles(xRg As Range, xSPathStr As Variant, xDPathStr As Variant) Dim xCell As Range Dim xVal As String Dim xFolder As Object Dim fso As Object Dim xF As Object Dim xStr As String Dim xFS As Object Dim xI As Integer On Error Resume Next If Dir(xDPathStr, vbDirectory) = "" Then MkDir (xDPathStr) End If For xI = 1 To xRg.Count Set xCell = xRg.Item(xI) xVal = xCell.Value If TypeName(xVal) = "String" And Not (xVal = "") Then On Error GoTo E1 If Dir(xSPathStr & xVal, 16) <> Empty Then FileCopy xSPathStr & xVal, xDPathStr & xVal End If End If E1: Next xI On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") Set xFS = fso.GetFolder(xSPathStr) For Each xF In xFS.SubFolders xStr = xDPathStr & "\" & xF.Name Call sCopyFiles(xRg, xF.ShortPath & "\", xStr & "\") If (CreateObject("scripting.FileSystemObject").GetFolder(xStr).Files.Count = 0) _ And (CreateObject("scripting.FileSystemObject").GetFolder(xStr).SubFolders.Count = 0) Then RmDir xStr End If Next End Sub

      • To post as a guest, your comment is unpublished.
        HelpMe · 10 months ago
        Can You help me with this? I copied the whole code and it's fine but I'd like to use only part of the file name and not create folder when copyiong file from subfolder. Let's say I have folder AAA with file 123-321.pdf and subfolder BBB with file 123_111.pdf
        In Excel column i have only "123" without any extension or "-" or "_" and I want to copy all files containing "123" from folder AAA to new folder CCC.

        Right now this code would only copy a files when the full name is written in excel column like "123-321.pdf" or would create whole new subfolder BBB in folder CCC if you look for "123_111.pdf"

        Looking forward to Your response as I'm not even a newbie in VBA just passing by :D
  • To post as a guest, your comment is unpublished.
    priya · 1 years ago
    works perfectly like a charm
  • To post as a guest, your comment is unpublished.
    sd · 1 years ago
    can anyone help to adapt this excellent code so the file range is fixed eg all filenames in column A until empty cell and pre set the from path as i always copy from the same source
    • To post as a guest, your comment is unpublished.
      mubashirazizch@gmail.com · 1 years ago
      use this code and keep A1 cell blank

      Sub Copymy1()
      Dim filelist As Variant
      Dim i As Long
      Dim filetocopy As String
      Dim copysource As String
      Dim Copydestination As String

      copysource = "C:\copyfrom\"
      Copydestination = "C:copyto\"
      filelist = ActiveWorkbook.Sheets(1).Range("A1").CurrentRegion.Value
      For i = 2 To UBound(filelist)
      FName = Dir$(copysource & "*.*")
      While FName <> ""
      If UCase(FName) = UCase(filelist(i, 1)) Then
      FileCopy copysource & FName, Copydestination & FName

      End If
      FName = Dir$()
      Wend
      Next i

      End Sub
  • To post as a guest, your comment is unpublished.
    Exe · 1 years ago
    Sorry I just saw the second script below...

    I do have one more (applicable) query... Is there a way to make the script pick a filtered selection on a column? Instead of consecutive cell ranges.. would there be a way to make it pick only some specific rows after a filter is applied?
    THANK YOU
  • To post as a guest, your comment is unpublished.
    Exe · 1 years ago
    Thank you SO MUCH for this. It worked perfectly at my end.
    I have one question... is it possible to modify this to copy the files into the second path instead of moving them? I would need to apply this feature but I do need the source files to remain in the source folders.
    Thank you!!!
  • To post as a guest, your comment is unpublished.
    Phil · 1 years ago
    Hi, Can this code be tweaked to look for partial file names using a wildcard? Thanks
  • To post as a guest, your comment is unpublished.
    sabin348 · 1 years ago
    How could this be adapted to paste into a list of multiple file paths instead of one path at a time?
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, sabin,
      Do you want to copy and paste the files which from multiple original folders instead of only one folder?
      • To post as a guest, your comment is unpublished.
        andrea · 1 years ago
        yes please

  • To post as a guest, your comment is unpublished.
    mmarques09 · 1 years ago
    If the reference doesn't exist the code break
    wich line shall I had to the code do a jump through the next reference without stop
  • To post as a guest, your comment is unpublished.
    Marco · 1 years ago
    An what happen if the file doesn't existe in the origin folder?
    the code breaks

    The code shall has a line to jump to another reference if doesn't exist
  • To post as a guest, your comment is unpublished.
    Kevin · 1 years ago
    HI, I am not an expert in VBA but need your Module and I did as you instruct but nothing copied from source folder to the new folder. and no error is shown
  • To post as a guest, your comment is unpublished.
    inasr · 2 years ago
    Any update of how to search on folder and subfolders
    • To post as a guest, your comment is unpublished.
      skyyang · 2 years ago
      Hi, Nasr,
      To move files from folder and subfolders based on cell values, please apply the below VBA code:
      Please try, hope it can help you!

      Sub movefiles()
      'Updateby Extendoffice
      Dim xRg As Range, xCell As Range
      Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog
      Dim xSPathStr As Variant, xDPathStr As Variant
      Dim xVal As String
      Dim fso As Object, folder1 As Object
      ' On Error Resume Next
      Set xRg = Application.InputBox("Please select the file names:", "KuTools For Excel", ActiveWindow.RangeSelection.Address, , , , , 8)
      If xRg Is Nothing Then Exit Sub
      Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
      xSFileDlg.Title = " Please select the original folder:"
      If xSFileDlg.Show <> -1 Then Exit Sub
      xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\"
      Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
      xDFileDlg.Title = " Please select the destination folder:"
      If xDFileDlg.Show <> -1 Then Exit Sub
      xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\"
      Call sMoveFiles(xRg, xSPathStr, xDPathStr)
      End Sub

      Sub sMoveFiles(xRg As Range, xSPathStr As Variant, xDPathStr As Variant)
      Dim xCell As Range
      Dim xVal As String
      Dim xFolder As Object
      Dim fso As Object
      Dim xF As Object
      Dim xStr As String
      Dim xFS As Object
      Dim xI As Integer
      On Error Resume Next
      If Dir(xDPathStr, vbDirectory) = "" Then
      MkDir (xDPathStr)
      End If
      For xI = 1 To xRg.Count
      Set xCell = xRg.Item(xI)
      xVal = xCell.Value
      If TypeName(xVal) = "String" And Not (xVal = "") Then
      On Error GoTo E1
      If Dir(xSPathStr & xVal, 16) <> Empty Then
      FileCopy xSPathStr & xVal, xDPathStr & xVal
      Kill xSPathStr & xVal
      End If
      End If
      E1:
      Next xI
      On Error Resume Next
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set xFS = fso.GetFolder(xSPathStr)
      For Each xF In xFS.SubFolders
      xStr = xDPathStr & "\" & xF.Name ' Replace(xF.ShortPath, xSPathStr, xDPathStr)
      Call sMoveFiles(xRg, xF.ShortPath & "\", xStr & "\")
      If (CreateObject("scripting.FileSystemObject").GetFolder(xStr).Files.Count = 0) _
      And (CreateObject("scripting.FileSystemObject").GetFolder(xStr).SubFolders.Count = 0) Then
      RmDir xStr
      End If
      Next
      End Sub
      • To post as a guest, your comment is unpublished.
        Anita Singh · 9 months ago
        Hi skyyang,
        I want to copy or move files (.jpg, .png) any format from folder & its sub-folders. The above script is copying the whole folder containing the matched file

        Thanks & Regards,

      • To post as a guest, your comment is unpublished.
        inasr · 2 years ago
        That's perfect thank you
        but what about if I just wanted to copy files not moving it from subfolders only without the need of creating subfolders in the destination folder
        ie
        source folder X:\\parent
        inside parent is subfolders test1(file A), test2(file B) and test3(file C)
        then destination folder is "Y:\\destination" has all 3 files A, B, C without the subfolders

        Thank you very much
        • To post as a guest, your comment is unpublished.
          Mike · 2 years ago
          Hi Nasr, did you figure out how to do this? I am looking at a similar need at the moment.

          Copying a selection of files from various subfolders to a single folder
          • To post as a guest, your comment is unpublished.
            inasr · 1 years ago
            Hi Mike
            I kind of did BUT indirectly, so what I did is modify the code to copy the files not move them with the subfolder
            then with CMD file move the file from subfolders to the main folder then delete the empty subfolder
            this is what I did

            Sub Copyfiles()
            'Updateby Extendoffice
            Dim xRg As Range, xCell As Range
            Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog
            Dim xSPathStr As Variant, xDPathStr As Variant
            Dim xVal As String
            Dim fso As Object, folder1 As Object
            ' On Error Resume Next
            Set xRg = Application.InputBox("Please select the file names:", "KuTools For Excel", ActiveWindow.RangeSelection.Address, , , , , 8)
            If xRg Is Nothing Then Exit Sub
            Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
            xSFileDlg.Title = " Please select the original folder:"
            If xSFileDlg.Show <> -1 Then Exit Sub
            xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\"
            Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
            xDFileDlg.Title = " Please select the destination folder:"
            If xDFileDlg.Show <> -1 Then Exit Sub
            xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\"
            Call sCopyFiles(xRg, xSPathStr, xDPathStr)
            End Sub

            Sub sCopyFiles(xRg As Range, xSPathStr As Variant, xDPathStr As Variant)
            Dim xCell As Range
            Dim xVal As String
            Dim xFolder As Object
            Dim fso As Object
            Dim xF As Object
            Dim xStr As String
            Dim xFS As Object
            Dim xI As Integer
            On Error Resume Next
            If Dir(xDPathStr, vbDirectory) = "" Then
            MkDir (xDPathStr)
            End If
            For xI = 1 To xRg.Count
            Set xCell = xRg.Item(xI)
            xVal = xCell.Value
            If TypeName(xVal) = "String" And Not (xVal = "") Then
            On Error GoTo E1
            If Dir(xSPathStr & xVal, 16) <> Empty Then
            FileCopy xSPathStr & xVal, xDPathStr & xVal
            End If
            End If
            E1:
            Next xI
            On Error Resume Next
            Set fso = CreateObject("Scripting.FileSystemObject")
            Set xFS = fso.GetFolder(xSPathStr)
            For Each xF In xFS.SubFolders
            xStr = xDPathStr & "\" & xF.Name ' Replace(xF.ShortPath, xSPathStr, xDPathStr)
            Call sCopyFiles(xRg, xF.ShortPath & "\", xStr & "\")
            If (CreateObject("scripting.FileSystemObject").GetFolder(xStr).Files.Count = 0) _
            And (CreateObject("scripting.FileSystemObject").GetFolder(xStr).SubFolders.Count = 0) Then
            RmDir xStr
            End If
            Next
            End Sub



            then copy the following lines to a new notepad then save it as cmd call it whatever

            for /r %%a IN (*.*) do (
            move /y "%%a" "%cd%"
            )
            for /f "delims=" %%d in ('dir /s /b /ad ^| sort /r') do rd "%%d"



            make sure to copy the code as is 4 lines
            hope that help
            • To post as a guest, your comment is unpublished.
              Tim · 1 years ago
              You can achieve the same result using only the VBA if you add a ' before the & "\" & xF.Name in the below line.
              This still copies from subfolders but copies to a single level folder.

              xStr = xDPathStr & "\" & xF.Name ' Replace(xF.ShortPath, xSPathStr, xDPathStr)
              Becomes
              xStr = xDPathStr '& "\" & xF.Name ' Replace(xF.ShortPath, xSPathStr, xDPathStr)
            • To post as a guest, your comment is unpublished.
              inasr · 1 years ago
              make sure to put the cmd file in the same folder that you copy the files and subfolders to then double click it
  • To post as a guest, your comment is unpublished.
    ADOLFO · 2 years ago
    buenas noches, alguien sabe que tengo que modificar para que me mueva carpetas y no solo archivos?
  • To post as a guest, your comment is unpublished.
    jonathan · 2 years ago
    thanks so much !
  • To post as a guest, your comment is unpublished.
    Michael · 2 years ago
    Has anyone figured out how to copy files that are located in multiple subfolders of the main directory, and paste into another folder directory? Also does this transfer method only work for folders on the C drive? I am trying to copy files from our directory that includes multiple subfolders where several files are stored located in Microsoft Sharepoint, to a folder on my C drive.

    Any help would be much appreciated!
  • To post as a guest, your comment is unpublished.
    julien · 2 years ago
    hi do you know how to search also on the subfolder ?
  • To post as a guest, your comment is unpublished.
    technicallyspecific@gmail.com · 2 years ago
    Works great - thank you! However-->>>Can this be adjusted to use a PARTIAL FILE NAME? If so, can you help show how?
    In other words, if file name on the Excel sheet list of filenames is: OW4234TR_J19031.txt (I'd like it to only look at last 5 chars "19031" which is a Julian Date and move a range of files... (anything with a Julian Date of 19092 thru 19120) into the March folder.. The ultimate over-arching task is to locate any files that have Julian dates for March and put those in the Fiscal March Folder "06-Mar" , April into the April folder "07-Apr" and so on...so Fiscal reconciliations by month can then take place.. TIA for any help anyone can offer to expedite this time consuming hunt and picking process. =-)
  • To post as a guest, your comment is unpublished.
    Fer · 2 years ago
    en el codigo que copia ¿como puedo colorear el nombre de la lista que no encuentre?
  • To post as a guest, your comment is unpublished.
    Johnette · 2 years ago
    I cannot get either version to work in Windows 10.


    Argggg
  • To post as a guest, your comment is unpublished.
    Andy · 3 years ago
    Any tips on how to modify the code to add a wide card? I have an archive of hundreds of PDF files that are 10 digit numbers and revision level (XXXXXXXXXX_REVA). I can export a list of file names very easily from our ERP system, but the list is missing the revision and file extension. Is there a way to add wild cards into the program to ignore everything BUT the 10 digit number?
  • To post as a guest, your comment is unpublished.
    PWD · 3 years ago
    Hello,
    how to make this code copy files from subfolders?
  • To post as a guest, your comment is unpublished.
    Gokury · 3 years ago
    Hi Guys,

    How I need to change '' If TypeName(xVal) = "String" And xVal <> "" Then '' to move files based on partial file name.


    Thanks in advance,
    Best regards, P
    • To post as a guest, your comment is unpublished.
      technicallyspecific@gmail.com · 2 years ago
      Did you ever find out HOW to use a PARTIAL FILE NAME? I need that as well...
      In other words, if file name on the Excel sheet list is: OW4234TR_J19031.txt (I'd like it to only look at last 5 chars "19031" which is a Julian Date and move a range of files... anything with a Julian Date of 19031 thru 19075..
      • To post as a guest, your comment is unpublished.
        eric · 2 years ago
        I also would require the partial file name vba modification. Did you ever get a response?
        • To post as a guest, your comment is unpublished.
          Alexandru Matei · 11 months ago
          I am interested in exactly the same solution! Did anyone get the answer?
          I have a P/N list in a column, and I want a piece of code that looks in a parent folder that has several subfolders after files with the name indicated by the list, but only partially, because I don't know the file extension and in many cases for a single P/N in the list, I have several files differentiated by the existence of a suffix that does not always have the same pattern, such as xxxx_1, xxxx_2, xxx (1), xxxx [1], xxxx- (a ), xxxx_ (b) ...., but I need to copy in the destination folder, all the instances of the files that contain in their name the P/N.
          Please help me to not do this job manually for 34078 files that today finds in parent folder and subfolders
  • To post as a guest, your comment is unpublished.
    Sidney · 3 years ago
    Você não tem noção de como me ajudou com esse script... Muito bom!!! Obrigado!!!
  • To post as a guest, your comment is unpublished.
    Robinson · 3 years ago
    Obrigado!!!!
  • To post as a guest, your comment is unpublished.
    Alisson · 3 years ago
    Era exatamente isso que eu precisava!!!

    Muito Obrigado!!!!
  • To post as a guest, your comment is unpublished.
    Raki · 3 years ago
    Hi, In the source folder, I wish to set it as a constant from a cell, for example the path entered in a particular cell, like A1, should be treated as the source folder. How to do this?
  • To post as a guest, your comment is unpublished.
    madhan · 3 years ago
    It is the nice macro.Real helpful for me. but I need some update macro.this used to copy the files from single folder to another folder. we need copy files from folder and subfolder to another folder.