Hi group,
I have a querry- file search application macro which searches all directories and subdirectories found within the provided string path and brings in specific data from spreadsheets in those directories. I would like to have the ability to exclude some of the subdirectories which are currently being querried.
I'm wondering if it is possible to add additional code that will allow me to either include or exclude specific directories being querried.
Here's an excerpt of the code:
Set fs = Application.FileSearch
With fs
.LookIn = Lookinpath
.SearchSubFolders = True
.FileName = "*bom*.xls"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
If InStr(1, .FoundFiles(i), "COMPLETED") > 0 Then 'this is the test for completed files
Application.StatusBar = "Actioning Completed " & i & " of " & .FoundFiles.Count & " Foundfiles"
Workbooks.Open FileName:=.FoundFiles(i), UpdateLinks:=False
Set sf = FSO.getFolder(ActiveWorkbook.Path)
'do a test to see if the sheet to use is MASTER or only sheet in file
If ActiveWorkbook.Sheets.Count = 1 Then 'action the only sheet
startrow = Range("A:A").Find(what:="NUMBER").Row + 1
For j = startrow To Cells(Rows.Count, 1).End(xlUp).Row
If Not IsEmpty(Cells(j, 1)) Then
outrow = OutPL.Cells.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
OutPL.Cells(outrow, 1).Value = Cells(j, 1).Value
OutPL.Cells(outrow, 2).Resize(1, 3).Value = .FoundFiles(i)
Since the directory names are part of the string path, would it be possible to add something like the following to the code?
OutPL.Cells(outrow, 2).Resize(1, 3).Value = .FoundFiles(i) - InStr(1, .FoundFiles(i), "\TMP\")
or
If InStr(1, .FoundFiles(i), "\TMP\") > 0 Then Do Nothing
Else
'Then Do the following
Any help is appreciated.
Thanks,
BDB
Bookmarks