Copy files from one directory to another with vba

MrTinkertrain

Board Regular
Joined
Feb 7, 2007
Messages
66
Office Version
  1. 365
  2. 2021
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
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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:
Upvote 0
Maybe this page will help
Copy and Move files and folders


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
 
Upvote 0
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
 
Upvote 0
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:
[color=darkblue]Sub[/color] Copy_Files()
    [color=darkblue]Dim[/color] cell [color=darkblue]As[/color] Range
    [color=darkblue]For[/color] [color=darkblue]Each[/color] cell [color=darkblue]In[/color] Range("E1", Range("E" & Rows.Count).End(xlUp))
        FileCopy Source:=cell.Value, Destination:=cell.Offset(, 2).Value
    [color=darkblue]Next[/color] cell
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,037
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top