Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: GetOpenFileName - filter list based on part of the file pref

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Wisconsin - USA
    Posts
    62
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I have a need to use the GetOpenFileName method, to select a file.

    The default directory where the files are stored have different names....
    123_ABC.txt
    333_ABC.txt
    999_WYZ.txt

    I can use the FileFilter property to narrow down *.txt files.

    But I need to only display the _ABC.txt files. I can get it to work only manually through the dialog...i.e. type in: 'ABC.txt' should filter the list in the dialog to: 123_ABC.txt & 333_ABC.txt

    Does anyone know how to programatically match the file name just like the "File name" option in the dialog box itself?

    The provided example via this link did not work:
    http://mrexcel.com/board/viewtopic.p...c=6480&forum=2

    When we run it, we see the following in the
    Files of Type drop-down list:
    my Files(*_ABC.txt.*)

    We also tried it without the last ".", but it just displayed:
    my Files(*_ABC.txt*)

    However, no files defined of that type display. Any suggestions would be great.
    Perhaps this filter should be applied to the "File Name" entry box instead?

  2. #2
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Your file filter needs to be defined as;

    sFilter = "my Files (*ABC.txt)" & Chr(0) & "*ABC.txt" & Chr(0)


    Kind Regards,
    Ivan F Moala From the City of Sails

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Wisconsin - USA
    Posts
    62
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks Ivan!
    That worked!
    Have a super day!

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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