none
Need help finding file within a subFolder RRS feed

  • Question

  • My task is to find a pdf file in a folder within a sub folder then display that pdf file. I am using VBA code but in not sure of a way to approach this problem.  I thought of using Dir() but I'm not familiar with it any suggestions?
    Friday, July 10, 2015 3:42 PM

Answers

  • Yes, you can loop all sub folders of a folder.

    Look here:

    https://social.msdn.microsoft.com/Forums/en-US/8f9d2d81-81c0-4067-8d5d-a2941a13d324/searching-folders-and-subfolders

    and here:

    http://stackoverflow.com/questions/22645347/loop-through-all-subfolders-using-vba

    and here:

    http://stackoverflow.com/questions/20687810/vba-macro-that-search-for-file-in-multiple-subfolders

    • Marked as answer by Oneill M Friday, July 10, 2015 4:44 PM
    Friday, July 10, 2015 4:39 PM

All replies

  • You should be able to Google up some code for this.

    The idea is to start with the name of the directory of interest, and traverse over the contents of that directory.

    Test the type of the each item in the directory.

    If it’s a file, and it satisfies the name requirement, you’re done.

    If it’s a directory, concatenate the name of that directory to the one the function is currently active in, and use your search function on the new directory (recursively) until you find the file, or you determine that no such file exists.

    Roughly speaking.

     


    peter n roth - http://PNR1.com, Maybe some useful stuff

    Friday, July 10, 2015 4:30 PM
  • Yes, you can loop all sub folders of a folder.

    Look here:

    https://social.msdn.microsoft.com/Forums/en-US/8f9d2d81-81c0-4067-8d5d-a2941a13d324/searching-folders-and-subfolders

    and here:

    http://stackoverflow.com/questions/22645347/loop-through-all-subfolders-using-vba

    and here:

    http://stackoverflow.com/questions/20687810/vba-macro-that-search-for-file-in-multiple-subfolders

    • Marked as answer by Oneill M Friday, July 10, 2015 4:44 PM
    Friday, July 10, 2015 4:39 PM
  • Thank you sooooo much! 
    Friday, July 10, 2015 4:44 PM