Esteemed Forum Participants and Lurkers:
===============================
EXCEL
I'm trying to identify a list of numbered files from a folder. They all have exactly the same format: fname_000.ext where "000" is any 3 numerals. I'm using the VBA FileSearch object, but it seems to prefix the filename with a wildcard "*" so that not only do all the files with the correct name get returned, but ANY file with any prefix before the correct name gets returned, such as "XXXX-fname_123.xls" ... YUK! How do I get it to ignore all files that do NOT fit the prototype?Why the devil does this return a file named "XXXX-fname_123.xls" ??? YUK!Code:'Create a FileSearch object Set fs = Application.FileSearch With fs .NewSearch .LookIn = "C:\Test" .SearchSubFolders = False .Filename = "fname_???.xls" '<<< This is what fails .MatchTextExactly = True If .Execute > 0 Then 'Step through each string in the FileDialogSelectedItems collection. For Each vrtSelectedItem In .FoundFiles 'vrtSelectedItem is a String: contains path of each selected item. 'This example simply displays the path in a message box. 'TEST TEST TEST TEST MsgBox "The path is: " & vrtSelectedItem 'END TEST Next vrtSelectedItem 'The user pressed Cancel. Else 'No file was selected End If End With
And how do I only return files that EXACTLY fit my template: fname_???.xls
Thank you for all comments, suggestions, and assistance.




Reply With Quote