+ Reply to Thread
Results 1 to 19 of 19

Excel VBA set a filter for a exact filename using MsoFileDialogPicker

  1. #1
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    Hi guys,
    I've been plying around with this code but cannot achieven what I want:

    Please Login or Register  to view this content.

    It's the red line that I am trying to use as filter.
    I know how this works and yes I can add code to check if the correct file was selected, but that's not it.
    I want the filetr to only show the AdminMEDEWERKER.xlsm when a folder is selected.
    The problem lies in the part in red, if I place *.xlsm it will show all xlsm files.

    Please Login or Register  to view this content.

    Anybody an idea?
    I also placed this question on the Tech Guy support forum: https://forums.techguy.org/threads/e...ledia.1238235/
    Last edited by Keebellah; 01-06-2020 at 06:32 AM. Reason: extra info
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    Don't think that is possible Hans...
    Could narrow down to...
    Please Login or Register  to view this content.
    Why would you want to have a user select to open only a specific file...
    Why not just open the file directly...

    Alternatively, you will have to add a snippet to see if the selected item is in fact the required file...
    Last edited by sintek; 01-06-2020 at 07:51 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    Hi, true, and yes, like I mentioned I have it working but the idea behind this is that the user has to select the folder where the file is located and I thought that the best way is to show only the the file answering the requirements thus that the filer only shows a filename that is the same as the requested file but it does not accept that parameter as a filter, list *.xlsm but if i say *AdminMEDERWERKER*.xlsm or other variations I just get an error.
    You see, that once the file is selected I just register the filepath in a setting for later use.
    Workarounds enough that work fine, but just trying to find another way.
    Will keep this post open for a day or two more and see if some comes up with an idea

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    Never seen an exact match Dialogue Picker Filter, but yep, would be interesting to see if there is a workaround other than checking if correct file is selected...

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    You could just use Dialogue to pick the folder and concatenate constant filename.
    Then use Dir function to check if file exists in the folder...

    But not sure if it's even worth it.

    AFAIK - FileDialog Filter can only be used for extension *.xxx or *.* for all.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker


  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    I found some code and played with it

    mdwAdminFile is a fulle filename in my case AdminMEDEWERKER.xlsm

    Please Login or Register  to view this content.

  8. #8
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    @sintek: the links do explain things but I have variations of the same. thanks for looking

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    This seems to work...
    I put multiple xlsm files in a folder and only the required one became available as a selection...
    In the VBA Editor's Tools menu, click References... scroll down to "Microsoft Shell Controls And Automation"

    Please Login or Register  to view this content.
    Or without setting reference...
    Please Login or Register  to view this content.
    Last edited by sintek; 01-06-2020 at 12:39 PM.

  10. #10
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    Well it works but not with the idea I wanted.
    My code does the following, once I run it it now fills a Listbox with the folders where ti's found and all the user has to do is select that item he/she wants

    But, I like your solution will do some test with it, thanks again.
    Attached Images Attached Images

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    Okay...The plot thickens...
    So why not just loop all folders and files and if a file is named "AdminMEDEWERKER.xlsm" then add that path to the list for the user then to select...
    Please Login or Register  to view this content.
    OR, Am I missing something...Why the initial Dialog Picker option...
    Attached Files Attached Files
    Last edited by sintek; 01-06-2020 at 01:15 PM.

  12. #12
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    Of you start in let’s dat G’s root directory the recursieve search takes longer. The Userform works such that the user double clicks the field to open the folder picker and once a folder is selected, click the optionbutton to run the macro and list the found folders in the listbox

  13. #13
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    Would like to see this pan out...Wanna upload a sample file...

  14. #14
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    I'll extract that part of the code and paste it in a sample file.

  15. #15
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    Here's the file the code is extraction took some time
    There a Const mwdAdminFile that you can modify the string to a file name you want to look for.

    Open the file and double-click the yellow cell
    Attached Files Attached Files

  16. #16
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    So...I am assuming you have solved your requirement or is there "more than meets the eye"

  17. #17
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    Yep, it's solved but just wanted to share the solution. The application in which I am using this works.
    The reason is simple, the user decides that the file's location has to be modified so he/she selects a new one. There are a certain number of extra files in that same location that if present have to be moved from the old location to the new one.
    So the user must be sure that the 'move from' location does indeed cold the main file which is the fixed name, and if that's true then the move routine triggers and all the required files are moved to to 'move to' location.
    I'll mark it as solved, thanks for looking and making suggestions.

  18. #18
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    Glad you got it sorted...Am thankful for this thread as I too have learned new alternatives...

  19. #19
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Excel VBA set a filter for a exact filename using MsoFileDialogPicker

    we're never too old to learn

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. how to filter exact text
    By faizzsheikh in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-29-2016, 07:53 AM
  2. Filter column by exact match?
    By mikey42979 in forum Excel General
    Replies: 6
    Last Post: 06-20-2013, 11:21 AM
  3. Macro to filter exact sum total
    By pkk1964 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-05-2011, 06:36 AM
  4. Filter function - exact match...
    By pmguerra in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-20-2006, 09:48 AM
  5. [SOLVED] Advanced Filter for exact value
    By hari in forum Excel General
    Replies: 3
    Last Post: 11-10-2005, 05:15 PM
  6. Advanced Filter for exact value
    By hari in forum Excel General
    Replies: 2
    Last Post: 11-10-2005, 04:23 PM
  7. Advance filter search does not filter an exact match
    By cfiiland in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2005, 08:05 AM

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