copy multiple extension files in all folders and subfolders based on excel sheet

PPARAB

New Member
Joined
Dec 25, 2016
Messages
5
I have to multiple extension files copy in all folders and subfolders based on excel sheet.
eg.

Column A Column B Column C
1 File Name From Path To Path
2 Test C:\Storage C:\Active
3 Test1 C:\Storage C:\Active
4 Test2 C:\Storage C:\Active
5 Test3 C:\Storage C:\Active
6 Test4 C:\Storage C:\Active

Please provide VB code

Any help will be greatly appreciated. Thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this. I don't know what the file extensions are, so I'm using a wildcard. If you know the file extension, you can include it in column A and remove the & ".*". Alternatively if they're all the same file extension, replace the * with the extension.
Code:
Sub CopyMacro
Set fs = CreateObject("Scripting.FileSystemObject")
n = 2
Do While Range("A" & n).Value <> ""
fs.CopyFile Range("B" & n).Value & "\" & Range("A" & n).Value & ".*" Range("C" & n).Value & "\"
n = n + 1
Loop
End Sub
You need to make sure that there are no gaps in your file list, as the macro will stop at the first gap.
 
Last edited:
Upvote 0
Try this. I don't know what the file extensions are, so I'm using a wildcard. If you know the file extension, you can include it in column A and remove the & ".*". Alternatively if they're all the same file extension, replace the * with the extension.
Code:
Sub CopyMacro
Set fs = CreateObject("Scripting.FileSystemObject")
n = 2
Do While Range("A" & n).Value <> ""
fs.CopyFile Range("B" & n).Value & "\" & Range("A" & n).Value & ".*" Range("C" & n).Value & "\"
n = n + 1
Loop
End Sub
You need to make sure that there are no gaps in your file list, as the macro will stop at the first gap.

Thanks for quick reply
Extension are as below
.pdf , .dxf , .IDF , .matc
 
Upvote 0
Don't think you can upload an excel file to this site, plus haven't got access to excel today anyway. But if you open a new spreadsheet, go on to the developer tab, there's a VBA option, and you can open a window to paste the code into.
If there are multiple file extensions, probably best to build them into column A and remove the & ".*" from my code.
 
Upvote 0
Don't think you can upload an excel file to this site, plus haven't got access to excel today anyway. But if you open a new spreadsheet, go on to the developer tab, there's a VBA option, and you can open a window to paste the code into.
If there are multiple file extensions, probably best to build them into column A and remove the & ".*" from my code.


I have go to as per your instruction shown error as

Compile error:
Syntax error
 
Upvote 0
Sorry, I can see that I have missed a comma. It should go before Range("C" & n).Value & ""
So my code is now
Code:
Sub CopyMacro
Set fs = CreateObject("Scripting.FileSystemObject")
n = 2
Do While Range("A" & n).Value <> ""
fs.CopyFile Range("B" & n).Value & "\" & Range("A" & n).Value & ".*", Range("C" & n).Value & "\"
n = n + 1
Loop
End Sub
 
Upvote 0
Sorry, I can see that I have missed a comma. It should go before Range("C" & n).Value & ""
So my code is now
Code:
Sub CopyMacro
Set fs = CreateObject("Scripting.FileSystemObject")
n = 2
Do While Range("A" & n).Value <> ""
fs.CopyFile Range("B" & n).Value & "\" & Range("A" & n).Value & ".*", Range("C" & n).Value & "\"
n = n + 1
Loop
End Sub

Shown error for below line
fs.CopyFile Range("B" & n).Value & "" & Range("A" & n).Value & ".*", Range("C" & n).Value & ""
Can't execute code in break mode.
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,144
Members
448,552
Latest member
WORKINGWITHNOLEADER

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