|
-
Jun 2nd, 2005, 11:35 AM
#1
Thread Starter
Frenzied Member
EXCEL: FileSearch seems to prefix filename with "*" YUK! [Resolved]
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?
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
Why the devil does this return a file named "XXXX-fname_123.xls" ??? YUK!
And how do I only return files that EXACTLY fit my template: fname_???.xls
Thank you for all comments, suggestions, and assistance.
Last edited by Webtest; Jun 3rd, 2005 at 07:00 AM.
Reason: RESOLVED
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Jun 2nd, 2005, 06:26 PM
#2
Re: EXCEL: FileSearch seems to prefix filename with "*" YUK!
Well, you can correct for this error like so:
VB 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: " & Right$(vrtSelectedItem, Len(vrtSelectedItem) - InStr(vrtSelectedItem, "-"))
'END TEST
Next vrtSelectedItem
'The user pressed Cancel.
Else
'No file was selected
End If
End With
That should fix it but as to the cause I have no idea.
Cheers,
RyanJ
-
Jun 3rd, 2005, 06:59 AM
#3
Thread Starter
Frenzied Member
Re: EXCEL: FileSearch seems to prefix filename with "*" YUK!
Thanks Ryan ...
Yes, that's one way to do it, but it certainly is brain damaged. It is odd to note that the FileSearch works 'as expected' in Office '97! My default is Office 2002, and that is what is broken.
I think I'll just use a Dir loop. Immediately previous to the FileSearch operation, I use the FileDialog, and except for extension filtering (part of the time I'm looking for PDFs which aren't recognized by MegaShaft), it works OK and returns the full file specification. The file spec and wild cards work perfectly in Dir.
Thanks again ...
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|