Copy files from one directory to another

jroo

Board Regular
Joined
May 22, 2003
Messages
157
Hello

I want to copy files from one directory and paste them to another. Currently I have a program which
1)goes to a specified directory
2)opens each indiividual excel file
3)saves it to the directory where i want it to be saved

Is there an easier way to just copy the files from one directory and pasting them to my intended directory (without having to open and save).

Something like:

C:\My Documents\ Original\*.xls copy

Paste to: C:\My Documents\Other\
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I'm probably missing something in your question here, but just use Windows Explorer, highlight the selected files with CTRL + C, navigate to the desired folder and paste.

Or use the 'find' command in the start menu if you want to copy excel files from more than one folder (Find, then advanced, then Microsoft Excel Files), copy the ones you want, then navigate to the required file using explorer, and paste.
 
Upvote 0
From help

Name oldpathname As newpathname

eg

OldName = "C:\MYDIR\OLDFILE"
NewName = "C:\YOURDIR\NEWFILE"

Name OldName As NewName
 
Upvote 0
I want to avoid "phsyically" copying files from a directory and pasting them to aonother. Let's say I have 30 directories to copy files from - on a routine basis (i.e. monthly). I want be able to run a macro, rather than going through windows explorere and opening and closing folders.

Please let me know if I'm making sense.
 
Upvote 0
Try this:

dim fs
dim strPath as String, strDestination as String

set fs = CreateObject("Scripting.FileSystemObject") 'Allows access to file system

strPath = activeworkbook.path
strDestination = "Path where you want your workbook to go"

fs.CopyFile strPath & "\*.*", strDest, True

Play around with that
 
Upvote 0
THANKS!!!! this worked brilliantly.

this will save me SOOO much time. I have one more question. If I rerun the code again using

fs.CopyFile strPath & "\*.*", strDest, True

will files automatically be overwritten, if they already exist? I ran the code, expecting a warning to come up..but it didn't. Does the "True" mean overwrite?
 
Upvote 0

Forum statistics

Threads
1,224,876
Messages
6,181,522
Members
453,050
Latest member
Obil

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