VBA Code to find a folder and store its path

  • Hello, I require code to search for a specific folder on my c:\ drive using a user input wildcard. Then, I would like to give the option to open the folder parth. Thanks in advance!

  • Hello and Welcome to the Forum :smile:


    Below is an example to open the File Dialog ..



    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Thanks for that! But not exactly what I am looking for. I would like to use an input box prompting a user to enter a search variable. Then upon submitting the macro will look in a preset Dir for a folder containing the variable. Then give the option to open the found folder.

  • Thanks for that! But not exactly what I am looking for. I would like to use an input box prompting a user to enter a search variable. Then upon submitting the macro will look in a preset Dir for a folder containing the variable. Then give the option to open the found folder.


    Understand your point ...


    However, you do need to rely on extremely disciplined users ... to always spell correctly their input searches ...unless you are planning on providing a Validation List of the possible search variables ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Ok, so theres no way to search a dir for a folder like this:


    Location: c:\test\test1\test2\


    User input: mark


    Search: c:\test\test1\test2 & *mark*


    If found: store path


    Would you like to open folder?: path


    Yes --> Open folder


    These are the steps I would like to follow. Just need to convert them to VBA :).

  • Once the user inputs mark ...


    Could you get a long list of subfolders for which their names would contain *mark* ...


    or ... are you 100% sure, thanks to your actual structure ... that the result can only be Nothing or 1 folder ...???

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hello,


    You could adapt the following macro to test if ... after the input of your Search Text ... the folder exists ...or not ...



    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!