.Execute vexing me

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I copied the following code elsewhere, so I know it must work:

strFiles = ""
With Application.FileSearch
.NewSearch
.LookIn = strDrive
.SearchSubFolders = True
.FileName = strFilename
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
For Each varItm In .FoundFiles
strTmp = fGetFileName(varItm)
If strFilename = strTmp Then
fReturnFilePath = varItm
Exit Function
End If
Next varItm
End If

Anyway, my issue is that when the ".Execute" line is encountered, it appears
as if the method isn't even being attempted. The program appears to run for
about 2 seconds, then goes right to the "End If" line associated with the
".Execute" line. It's as if the condition is automatically assigned a False
value before the method is allowed run.

I do have the correct references implemented. Am I missing something simple?

Thanks, as always.
 
I notice you are using .MatchTextExactly = True without setting the
..TextOrProperty property. Without testing, I can't be sure, but that may
cause it to return no files at all, which would make .Execute = 0.
The MatchTextExactly says return only files of .FileType that have the text
specified in .TextOrProperty property in either their body text or their
properties.
Before you change it, set a breakpoint at the .Execute line then step
through it to see where it is going. If it drops to the End If, that means
no files are being returned. If that is the case, try commenting out the
..MatchTextExactly line and running it again.
 
I found the issue. It appears I'm an imbicile. The file wasn't where I was
searching and I was misinterpreting the function itself. For what it's
worth, the .MatchTextExactly worked just fine.

Thanks for your help. Sorry I wasted your time.
 
Back
Top