I need to copy files from folders and subfolders, but the below code search for only subfolders inside the main folder. But there are also some subfolders inside the subfolders Eg : C:\abc\bca - for this abc is main folder and bca is subfolder, the code is working for this. For c:\abc\bca\cab or c:\abc\zxc\cvg it is not working in folders in subfolders, Please assist me. Thanks in Advance
Sub copy_files_from_subfolders()
Dim fso As Object
Dim fld As Object
Dim fsofile As Object
Dim fsofol As Object
Dim filename As String
Dim snumber As Double
snumber = InputBox("Enter the Number", "Message from D")
filename = "_PTA.pdf"
sourcepath = "\\chec.local\"
destinationpath = "R:\Desa"
If Right(sourcepath, 1) <> "\" Then
sourcepath = sourcepath & "\"
End If
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 InStr(1, fsofile.Name, snumber) = 1 Then
MsgBox "Documents Copied"
fsofile.Copy destinationpath
End If
Next
Next
End If
End Sub