Consulting

Results 1 to 6 of 6

Thread: Copy files by name from a folder to another

  1. #1
    VBAX Newbie
    Joined
    Apr 2020
    Posts
    4
    Location

    Copy files by name from a folder to another

    Hi. I have a list with specific file names (Sheet "Attachments list", range B2:B603). I need a macro that copies the files in this list from a source folder (that contains those files and a bunch of other files) to a destination folder.
    Help pls.
    Thanks!

  2. #2
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Hi and welcome to the forum

    See here
    Semper in excretia sumus; solum profundum variat.

  3. #3
    VBAX Newbie
    Joined
    Apr 2020
    Posts
    4
    Location
    Thank you, it worked!
    Last edited by Efusu; 04-27-2020 at 03:52 AM.

  4. #4
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    You're welcome!

    You can mark it 'Solved' by using the Thred Tools above.
    Semper in excretia sumus; solum profundum variat.

  5. #5
    VBAX Newbie
    Joined
    Mar 2020
    Posts
    3
    Location
    Dim filelist As Variant
    Dim i As Long
    Dim filetocopy As String
    Dim copysource As String
    copysource = SourceDir
    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, "C:\Copyto" & fname
    End If
    fname = Dir$()
    Wend
    Next i

  6. #6
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Binu, code is easier to read if it is indented and you should use Code Tags to wrap code, even copied code!
    Semper in excretia sumus; solum profundum variat.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •