Macro to copy files from one diretory into another

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,585
Office Version
  1. 2021
Platform
  1. Windows
I would like a macro to copy all .xls, xlsm workbooks from Directory Pull including sub-directories of Pull to directory "Summary profit Reports"

Your assistance in this regard is most appreciated
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi Ron

I want to copy all Excel files from folder C:\pull as well as the excel files in the sub-directories within the pull directory for eg C:\pull\br1 , C:\pull\BR2 etc to C:\summary profits



I have used your code below, but when running the macro , it comes up with message "Path now found and the following code iis highlighted

FSO.CopyFolder Source:=FromPath, Destination:=ToPath

It would be appreciated if you could assist in resolving the problem




Sub Copy_Certain_Files_In_Folder()
'This example copy all Excel files from FromPath to ToPath.
'Note: If the files in ToPath already exist it will overwrite
'existing files in this folder
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String

FromPath = "C:\pull" '<< Change
ToPath = "C:\summary profits" '<< Change"

FileExt = "*.xls" '<< Change
'You can use *.* for all files or *.doc for Word files
If Right(FromPath, 1) <> "\" Then
FromPath = FromPath & "\"
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If

FSO.CopyFolder Source:=FromPath, Destination:=ToPath
MsgBox "You can find the files and subfolders from " & FromPath & " in " & ToPath

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,537
Messages
6,160,405
Members
451,644
Latest member
hglymph

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