Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By AlphaFrog

Copy files from one directory to another with vba

This is a discussion on Copy files from one directory to another with vba within the Excel Questions forums, part of the Question Forums category; Hello Excel Gurus, I used to have some VBA code to copy files from one directory to another. Due to ...

  1. #1
    Board Regular
    Join Date
    Feb 2007
    Posts
    53

    Default Copy files from one directory to another with vba

    Hello Excel Gurus,

    I used to have some VBA code to copy files from one directory to another.
    Due to a crash of my external HD I've lost all the snippets of code I've collected over the years
    I can't reproduce the code i'm looking for, so here I am

    In col E I have a list of files which I want to be copied to the specific location which is in col G.

    Can someone help me out with some code to achieve this ?

    Many thanks in advance

    Best regards,

    Mike

  2. #2
    MrExcel MVP AlphaFrog's Avatar
    Join Date
    Sep 2009
    Posts
    10,951

    Default Re: Copy files from one directory to another with vba

    Is column E just a file name, or a full path and file name?

    Is column G just the destination path, or a path and new file name?

    Do the directories in column G already exist?

    Do you want to move the files or create a copy in the destination?

    Perhaps a couple of examples would help.
    Last edited by AlphaFrog; Apr 23rd, 2013 at 03:31 PM.
    Paste your Excel data to the forum...
    MrExcel HTML Maker or Excel Jeanie

    Surround your pasted VBA code with code tags e.g.;
    [CODE]your VBA code here[/CODE]
    The pound # icon in the Advanced forum editor will apply the code tags around the highlighted text.

  3. #3
    Board Regular Ron de Bruin's Avatar
    Join Date
    Aug 2006
    Location
    Netherlands
    Posts
    219

    Default Re: Copy files from one directory to another with vba

    Maybe this page will help
    Copy and Move files and folders


    Quote Originally Posted by MrTinkertrain View Post
    Hello Excel Gurus,

    I used to have some VBA code to copy files from one directory to another.
    Due to a crash of my external HD I've lost all the snippets of code I've collected over the years
    I can't reproduce the code i'm looking for, so here I am

    In col E I have a list of files which I want to be copied to the specific location which is in col G.

    Can someone help me out with some code to achieve this ?

    Many thanks in advance

    Best regards,

    Mike

  4. #4
    Board Regular
    Join Date
    Feb 2007
    Posts
    53

    Default Re: Copy files from one directory to another with vba

    Quote Originally Posted by AlphaFrog View Post
    Is column E just a file name, or a full path and file name?

    Is column G just the destination path, or a path and new file name?

    Do the directories in column G already exist?

    Do you want to move the files or create a copy in the destination?

    Perhaps a couple of examples would help.
    Hi Alphafrog,

    - Both column E and G are full paths and file names.
    - The directories in col G already exist
    - I intend to copy the files to the destination directory and leave the original files in the source

    So in col E is something like :

    g:\Pictures\Original\Big\7413.jpg

    and in col G is something like :

    h:\Pictures\Copy\Big\7413.jpg

    I hope I've answered your questions

  5. #5
    MrExcel MVP AlphaFrog's Avatar
    Join Date
    Sep 2009
    Posts
    10,951

    Default Re: Copy files from one directory to another with vba

    Quote Originally Posted by MrTinkertrain View Post
    Hi Alphafrog,

    - Both column E and G are full paths and file names.
    - The directories in col G already exist
    - I intend to copy the files to the destination directory and leave the original files in the source

    So in col E is something like :

    g:\Pictures\Original\Big\7413.jpg

    and in col G is something like :

    h:\Pictures\Copy\Big\7413.jpg

    I hope I've answered your questions
    Code:
    Sub Copy_Files()
        Dim cell As Range
        For Each cell In Range("E1", Range("E" & Rows.Count).End(xlUp))
            FileCopy Source:=cell.Value, Destination:=cell.Offset(, 2).Value
        Next cell
    End Sub
    antialias401 likes this.
    Paste your Excel data to the forum...
    MrExcel HTML Maker or Excel Jeanie

    Surround your pasted VBA code with code tags e.g.;
    [CODE]your VBA code here[/CODE]
    The pound # icon in the Advanced forum editor will apply the code tags around the highlighted text.

  6. #6
    Board Regular
    Join Date
    Feb 2007
    Posts
    53

    Default Re: Copy files from one directory to another with vba

    Thank you very much, Alphafrog.

    Works like a charm

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com