Copy list of files to a certain folder..

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,750
Hi all,

I have a list of filenames (including file type extension) in sheet1, range A1:A30. Not all of them are xls file, some are pdf.

These files can be found under D:\Folder

Is there a way I can run a VBA code to locate each of these filenames under D:\Folder and save them under e.g. D:\MyFile\Docs ?

Thanks
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi
Try these codes
Code:
Sub patsys()
Dim x As Long, a As Long
Dim b As String
x = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For a = 1 To x
b = Sheets("Sheet1").Cells(a, 1)
FileCopy "D:\Folder\" & b, "D:\MyFile\Docs\" & b
Next a
End Sub
Ravi
 
Upvote 0
Hi
Try these codes
Code:
Sub patsys()
Dim x As Long, a As Long
Dim b As String
x = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For a = 1 To x
b = Sheets("Sheet1").Cells(a, 1)
FileCopy "D:\Folder\" & b, "D:\MyFile\Docs\" & b
Next a
End Sub
Ravi

Hi Ravishankar,

Thanks for your post. HOwever I am getting debug error, highlighting the line:

FileCopy "D:\Folder\" & b, "D:\MyFile\Docs\" & b

Would you know why?
 
Upvote 0

Forum statistics

Threads
1,203,605
Messages
6,056,229
Members
444,852
Latest member
MJaspering

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