Jambi46n2
Active Member
- Joined
- May 24, 2016
- Messages
- 260
- Office Version
- 365
- Platform
- Windows
Below is existing code from Ron de Bruin.
It works great for one path at a time, however I need it to work for multiple paths.
My screen shot below is the workbook I'm using and can't seem to get it passed one row with coping files and folders.
Additionally can I add a naming convention to every file copied as listed in F2 and F3?
Is this possible?
Thanks in advance!
It works great for one path at a time, however I need it to work for multiple paths.
My screen shot below is the workbook I'm using and can't seem to get it passed one row with coping files and folders.
Additionally can I add a naming convention to every file copied as listed in F2 and F3?
Is this possible?
Thanks in advance!
VBA Code:
Sub Copy_Folder()
'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.
If MsgBox("Copy Files to New Folder?", vbYesNo) = vbNo Then Exit Sub
Dim fso As Object
Dim FromPath As String
Dim ToPath As String
FromPath = [From_Path] '<< Change
ToPath = [To_Path] '<< 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 "Files Have Been Copied to New Folder"
End Sub