+ Reply to Thread
Results 1 to 10 of 10

More than one Root Path with max depth

  1. #1
    Registered User
    Join Date
    05-19-2021
    Location
    Netherlands
    MS-Off Ver
    Version 2104
    Posts
    33

    Post More than one Root Path with max depth

    Currently I am using the following code to search for a folder in one directory, namely V:/.
    Is it possible to user more than one path in this code with a max folder depth per path?

    E.g.

    v:/Folder 1/ (only this folder, block subfolder search)
    v:/Folder 2/ (only this folder, block subfolder search)
    V:/Folder 3/Subfolder/ (only this folder and 1 subfolder, block deeper subfolders)

    Please Login or Register  to view this content.

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: More than one Root Path with max depth

    You'd have to set a maximum depth and then keep track of it during recursion. Something like this:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Registered User
    Join Date
    05-19-2021
    Location
    Netherlands
    MS-Off Ver
    Version 2104
    Posts
    33

    Re: More than one Root Path with max depth

    Thank you very much for the reply, I will try this out right away.

    One more thing though. Currently the VBA code root path is set as: strRoot = "V:\"
    Now the code will search the entire drive.

    How can I make the code so that it only searches the following directories with each having their own depth set?

    v:/Folder 1/ (only this folder, block subfolder search)
    v:/Folder 2/ (only this folder, block subfolder search)
    V:/Folder 3/Subfolder/ (only this folder and 1 subfolder, block deeper subfolders)

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: More than one Root Path with max depth

    Different calls to FindFolder ...

    Please Login or Register  to view this content.
    WBD

  5. #5
    Registered User
    Join Date
    05-19-2021
    Location
    Netherlands
    MS-Off Ver
    Version 2104
    Posts
    33

    Re: More than one Root Path with max depth

    Again much appreciated.

    I've created the following VBA Code

    Please Login or Register  to view this content.
    What it does: I press a cell in Excel and it should then find the directory and open the folder using my StringID.

    Now I have two questions:

    Firstly: Have I implemented the different calls to FindFolder the right way?

    Secondly: When I execute the above VBA I get the following error: compile error: variable not defined

    Attachment 780397

  6. #6
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: More than one Root Path with max depth

    You're missing the declaration for fso. Try this:

    Please Login or Register  to view this content.
    WBD

  7. #7
    Registered User
    Join Date
    05-19-2021
    Location
    Netherlands
    MS-Off Ver
    Version 2104
    Posts
    33

    Re: More than one Root Path with max depth

    I hope this is my last question.

    If my Folder name is "12345" and my StrID is also "12345" its working perfectly!

    But when my Folder name is "12345 Hello World" but my StrID "12345" its unable to find my folder.
    I cant seem to find anything in the VBA code that's different compared to my original VBA code where I can determine a difference towards just searching a part of my folder name.

    Is there anything I can do where it finds my folder with just a part of the folders name?

  8. #8
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: More than one Root Path with max depth

    I didn't realise partial matches was a requirement. Try like this instead then:

    Please Login or Register  to view this content.
    WBD

  9. #9
    Registered User
    Join Date
    05-19-2021
    Location
    Netherlands
    MS-Off Ver
    Version 2104
    Posts
    33

    Re: More than one Root Path with max depth

    It worked! thanks a lot!
    Last edited by Nebucanezars; 05-13-2022 at 09:56 AM.

  10. #10
    Registered User
    Join Date
    05-19-2021
    Location
    Netherlands
    MS-Off Ver
    Version 2104
    Posts
    33

    Re: More than one Root Path with max depth

    Again, much appreciated for all the help and learning in the process.

+ 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. Out of my depth
    By MichaelTzu in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-03-2019, 05:49 PM
  2. Depth of bar in excel
    By rentb23 in forum Excel General
    Replies: 1
    Last Post: 02-25-2016, 01:38 PM
  3. Replies: 8
    Last Post: 04-04-2015, 08:45 AM
  4. [SOLVED] macro: insert picture based on workbook location, not picture root path.
    By NicksDad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2012, 07:47 AM
  5. In depth FTP question.
    By swoop99 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-22-2012, 09:20 AM
  6. root file path
    By ashishprem in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2006, 05:20 AM
  7. Excel Depth
    By Manish in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 09-28-2005, 01:05 PM

Tags for this Thread

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