Copy file from one folder to multiple others.

KrisWain320

New Member
Joined
Feb 4, 2016
Messages
10
Hi,

I am trying to write a simple VBA that will allow me to copy a file into a given folder, run the macro and then copy this file into multiple other folders (i.e. 5 or more other folders). I am struggling to figure out how to add the multiple paths into the code.

The code:

Sub Copy_Folder()
Dim FSO As Object
Dim FromPath As String
Dim ToPath1 As String
Dim ToPath2 As String


FromPath = "C:\Users\kwain1\Desktop\Old"
ToPath1 = "C:\Users\kwain1\Desktop\New1"


If Right(FromPath, 1) = "" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If


If Right(ToPath, 1) = "" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
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:=ToPath1
MsgBox "You can find the files and subfolders from " & FromPath & " in " & ToPath


End Sub


The source folder and destination folder are just test ones currently, I plan on changing them to the required ones when the code works.

If anyone has any ideas with how to make this automatic, i.e. when i drop the file in one folder it automatically copies it to the others, that would also be appreciated. Unsure if im barking up a far fetched tree or not with that one though.

Many Thanks
Kris
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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