+ Reply to Thread
Results 1 to 10 of 10

Exclude Files from GetOpenFileName based on File Name

  1. #1
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Exclude Files from GetOpenFileName based on File Name

    Hi

    I've this code to present the user of a list of files to open
    Please Login or Register  to view this content.
    and it presents with this screen screen capture.jpg

    I'd like the screen to NOT include any files with "Apple" in the file name. So, the fifth item on the list (Apple MTS (Template).xls) would not be displayed. ( I've tried to filter on "<> InStr(File.Name,"Apple")" with no success.

    Any way to accomplish this?
    Last edited by jaslake; 02-18-2011 at 02:18 PM.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Exclude Files from GetOpenFileName based on File Name

    Hello John,

    You can't do it using the Application.GetOpenFileName dialog. However, it may be possible with the API. I will have to look in library.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Exclude Files from GetOpenFileName based on File Name

    Thanks Leith...if you can point me in a direction, I'd appreciate it.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Exclude Files from GetOpenFileName based on File Name

    Hello John,

    The API allows more flexibilty but nothing to control the listing files by name, only by extension. Looks like you will have to use a UserForm and create your own.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Exclude Files from GetOpenFileName based on File Name

    Thanks Leith...I had considered the UserForm approach...hoped to find a shortcut

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Exclude Files from GetOpenFileName based on File Name

    Hi Leith

    I found this code (sorry, forgot to attribute) that works in Excel 2000...haven't been able to convert to Excel 2007 (Application.FileSearch issue). Don't ask you to do it for me...can you give me a clue?
    Please Login or Register  to view this content.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Exclude Files from GetOpenFileName based on File Name

    Hello John,

    The FileSearch object was abandoned in the 2007 release. You will need to use the File System Object. It is in the Microsoft Scripting Runtime library. You can add this reference to your project or late bind to it using the following statement in your code.
    Please Login or Register  to view this content.

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Exclude Files from GetOpenFileName based on File Name

    Hi Leith

    I was able to accomplish what I set out to due using your suggestion but I'm not happy with the code. I'm doing a recursive search but it's hard coded here
    Please Login or Register  to view this content.
    Here's the complete code
    Please Login or Register  to view this content.
    My concern is "What if I have SubSubSubFolders, etc, etc". Is there a way to go down the entire tree without hard coding it?

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Exclude Files from GetOpenFileName based on File Name

    Hello John,

    This example should help you. If the argument "IncludeSubfolders" is false then only the files of the main directory will be listed. If it is true then all files in all folders (Folders of subfolders, ad nauseam) will be listed.
    Please Login or Register  to view this content.

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Exclude Files from GetOpenFileName based on File Name

    Hi Leith

    After trial and error, I was able to adapt the code you provided. I was trying to build an array of the results...each time a new subfolder was opened, the array got reset. Had to take a different approach in building it.

    Thanks a lot for your assistance.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1