Results 1 to 3 of 3

Thread: EXCEL: FileSearch seems to prefix filename with "*" YUK! [Resolved]

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Resolved 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width