I have code below to copy files from a folder and sub-folder (these are on a network) where the name contains "*Template*2020.xlsm*"
When running the code I get get a run time error "object Required" and the code below is highlighted
It would be appreciated if someone could kindly amend my code
See full code below :
End Sub
When running the code I get get a run time error "object Required" and the code below is highlighted
Code:
Set FSO = CreateObject(“Scripting.FileSystemObject”)
It would be appreciated if someone could kindly amend my code
See full code below :
Code:
Sub copy_files_from_subfolders()
Dim FSO As Object, fld As Object
Dim fsoFile As Object
Dim fsoFol As Object
SourcePath = "abt\Sales\"
targetPath = "C:\Sales Reports\"
If Right(SourcePath, 1) <> " \" Then SourcePath = SourcePath & " \"
Set FSO = CreateObject(“Scripting.FileSystemObject”)
Set fld = FSO.GetFolder(SourcePath)
If FSO.FolderExists(fld) Then
For Each fsoFol In FSO.GetFolder(SourcePath).SubFolders
For Each fsoFile In fsoFol.Files
If fsoFile = "*Template*2020.xlsm*" Then
fsoFile.Copy targetPath
End If
Next
Next
End If
End Sub
End Sub