Excel vba: copy file from one folder to many folders simultaneously

yasawa

New Member
Joined
Dec 29, 2011
Messages
21
I want to copy files from one directory to several others, i (with searching help and ready code) succeeded in doing that, the problem is : the macro waits till it finishes copying all files from source to destination 1, then start copying to destination 2 I want either to: copy the 1st source to all destinations at the same time then moves to source 2 OR start copying all source files to destination 1 then moves to start copying all source files to destination 2 without waiting:
I use the following to code to copy:


Sub All()
<code>For Each C In Worksheets("Path").Range("A2:A21")
If C.Value = "" Then GoTo 1
Call CopyFolder

Application.ScreenUpdating = True
Next C</code> 1
End Sub
==========================================

Sub CopyFolder()
<code>Dim fso As Object
Dim FromPath As String
Dim ToPath As String

FromPath = "C:\video"
ToPath = C & ":\video"


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:=ToPath</code>

End Sub


Thanks
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
<code>Tried to make this array, but same waiting result:

Sub xArray()

Application.ScreenUpdating = False

Dim fso As Object
Dim FromPath As String
Dim ToPath As String
Dim Drive(1 To 2) As String
Drive(1) = "O"
Drive(2) = "P"
For i = 1 To 2
FromPath = "C:\video"
ToPath = Drive(i) & ":\video"

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:=ToPath

Next i

End Sub</code>
 
Upvote 0
Solved

Using the shell command, I called a .bat file that makes the copy process
Thanks
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,752
Members
448,989
Latest member
mariah3

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