PDA

View Full Version : Searching folders & subfolders from root for specific file & copy that file



aletukas
03-26-2013, 10:12 AM
Sub GetRailgear()
Dim R As Range
Dim SourcePath As String, DestPath As String, FName As String

'Setup source and dest path
SourcePath = "\\S1\sales\somecompany\KITS\"
DestPath = "C:\Users\Desktop\ORDERS\Current Order\"

'Visit each used cell in column A
For Each R In Range("C10")
'Search the file with the file mask from the cell
FName = Dir(SourcePath & R & ".xls")
'Loop while files found
Do While FName <> ""
'Copy the file
FileCopy SourcePath & FName, DestPath & FName
'Search the next file
FName = Dir()
Loop
Next
End Sub

Need some assistance with above code. I need to be able to search all folders and sub-folders from root directory for specific file name as specified by certain range and copy file to another existing folder. The above code does work but I have to specify exact source folder where file is located.