I should say that when I initially put your code into my function it worked
fine, but as I got into my function deeper, I could never get the search
folder to change.
First, here's a little explanation of what I'm trying to do, then the code
that doesn't accomplish it all:
(1) From a sub, I pass file name criteria (strFile = "201_P05*.*", for
example) and the path in which a certain instance of it is found.
(2) Search for instances of the file criteria within the folder.
(3) If more than one instance of the file criteria is found in a folder,
then the files in this folder are the ones I want to work with and blnStop is
set to true and the looping stops.
(4) On the other hand, if only one file in the searched folder fits the
search criteria, move up one folder level (attempted to do this per your
demonstration of ".." but it didn't move to another folder).
This is my code:
Function umRefineIt(strFile As String, strPath As String) As String
Dim strData As String, dirArray() As String, strFiles As String
Dim intCnt As Integer, intFiles As Integer
Dim blnStop As Boolean
'declare initial size of array variable (shrink later)
ReDim dirArray(1000)
With Application.FileSearch
.NewSearch
.LookIn = strPath
.SearchSubFolders = True
.FileName = strFile
.Execute
intFiles = .FoundFiles.Count
While .Execute(SortBy:=msoSortByFileName,
SortOrder:=msoSortOrderAscending) > 0 And blnStop = False
If intFiles > 1 Then
blnStop = True
For intCnt = 1 To intFiles
If InStr(.FoundFiles(intFiles), "grading") = 0 Then
intFiles = intFiles + 1
Next intCnt
End If
intCnt = 0
.NewSearch
.LookIn = strPath
.LookIn = ".."
.SearchSubFolders = True
.FileName = strFile
.Execute
Wend
End With