I am searching a directory for a filename using a wild card (*) in the file name. The problem is that the filesearch is picking up 2 files instead of one. for example, let's say there are 2 files in the folder named xFile.xls and File.xls. If I search for "File*.xls" it returns BOTH files when it should only be returning the File.xls. Below is an example of the code. Any ideas why the wildcard isn't working like it should?
Code:Dim FsSearch As Office.FileSearch Set FsSearch = Application.FileSearch TempName = "File" With FsSearch .NewSearch .LookIn = ThisWorkbook.Path + "\" .FileName = TempName & "*.xls" .SearchSubFolders = True .FileType = msoFileTypeExcelWorkbooks .LastModified = msoLastModifiedAnyTime .Execute 'Count of how many records are found For Each vaFile In .FoundFiles Workbooks.Open vaFile, False, False Next vaFile End With




Reply With Quote