I have written code to copy workbooks with .xlsm extensions and containing text Sales_Ledger from C:\users\howard\downloads to C:\sales ledgers
examples of file names below to be copies
BRMES Sales_Ledger RECON AUG.xlsm, BRSAU Sales_Ledger RECON AUG.xlsm etc
However no files are being copied
It would be appreciated if someone could kindly check & amend my code
Sub copy_files_from_subfolders()
Dim FSO As Object, fld As Object
Dim fsoFile As Object
Dim fsoFol As Object
SourcePath = "C:\Users\hcohen\Downloads"
targetPath = "C:\Sales Ledgers"
'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 LCase(fsoFile.Name) Like "*Sales_Ledger*.xlsm*" Then
fsoFile.Copy targetPath & fsoFile.Name
End If
Next
Next
End If
End Sub
Bookmarks