Hello,
I am new to Excel macros and I should create one where I copy all files from one folder to several other folders. There will be new files in the source folder every month and I should create something that copies them all to every destination folder easily.
Source folder shall be P:\source\another
There is about 20 destination folders. For example
[TABLE="width: 500"]
<tbody>[TR]
[TD]K:\destination\place_aar
[/TD]
[/TR]
[TR]
[TD]K:\destination\place_ppy
[/TD]
[/TR]
[TR]
[TD]etc...
[/TD]
[/TR]
</tbody>[/TABLE]
All of the files will likely be .pdf files
I have been searching and trying to do this for days, but as I am not yet familiar with Excel macros, I have not been able to do it.
I found the following code that copies all of the files to one folder and it worked, but I have not been able to change it so that the files will be copied to all folders at the same time. I have tried to make Excel sheet about all of the destination folders using something like range("A2:A20") but I can't seem to get it working.
Can anyone help me to change the code so that files will be copied to all of the folders I want?
Any help is greatly appreciated
I am new to Excel macros and I should create one where I copy all files from one folder to several other folders. There will be new files in the source folder every month and I should create something that copies them all to every destination folder easily.
Source folder shall be P:\source\another
There is about 20 destination folders. For example
[TABLE="width: 500"]
<tbody>[TR]
[TD]K:\destination\place_aar
[/TD]
[/TR]
[TR]
[TD]K:\destination\place_ppy
[/TD]
[/TR]
[TR]
[TD]etc...
[/TD]
[/TR]
</tbody>[/TABLE]
All of the files will likely be .pdf files
I have been searching and trying to do this for days, but as I am not yet familiar with Excel macros, I have not been able to do it.
I found the following code that copies all of the files to one folder and it worked, but I have not been able to change it so that the files will be copied to all folders at the same time. I have tried to make Excel sheet about all of the destination folders using something like range("A2:A20") but I can't seem to get it working.
Can anyone help me to change the code so that files will be copied to all of the folders I want?
Any help is greatly appreciated
Code:
Sub Copy_Folder()
'This example copy all files and subfolders from FromPath to ToPath.'Note: If ToPath already exist it will overwrite existing files in this folder'if ToPath not exist it will be made for you.
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
FromPath = "P:\source\another" '<< Change
ToPath = "C:\Users\Ron\Test" '<< Change ????
'If you want to create a backup of your folder every time you run this macro 'you can create a unique folder with a Date/Time stamp. 'ToPath = "C:\Users\Ron\" & Format(Now, "yyyy-mm-dd h-mm-ss")
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
MsgBox "You can find the files and subfolders from " & FromPath & " in " & ToPath
End Sub