Hello there, im in the process of writing a code that based on a cell value will create a new folder, name it to the cell value and then proceed to copy all the files from an already existing folder.
However, i keep getting an error : path not found
Here's the code
Thanks for any help
However, i keep getting an error : path not found
Here's the code
VBA Code:
Sub CopyFilesFromSubFolders()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim CurrentFile As Object
Dim dvCell As String
Dim destin As String
Dim path2 As String
dvCell = Workbooks("Scéno.xlsm").Sheets("Scén").Range("B11")
FromPath = "U:\origin\"
ToPath = "U:\target" & CStr(dvCell)
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FolderExists(ToPath) Then
FSO.CreateFolder ToPath
End If
path2 = ToPath & "\"
Debug.Print
For Each CurrentFile In FSO.GetFolder(FromPath).Files
CurrentFile.copy (FSO.BuildPath(path2, CurrentFile.Name))
Next
Set FSO = Nothing
Set CurrentFile = Nothing
End Sub