+ Reply to Thread
Results 1 to 22 of 22

Find folder path for string in cell

  1. #1
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Question Find folder path for string in cell

    As a preface, I tried to search for the solution to this for a while and was able to come up with some code, but it doesn't quite solve the issue.

    Please Login or Register  to view this content.
    The problem I'm having with this is that it doesn't go further into the folders within the specified folder. In other words if the directory was "C:\Users\name\directory 1\", and the folder was in "C:\Users\name\directory 1\directory 2\directory 3\folder", I'd like it to go in there and find it.

    Is there any way to do this?
    Last edited by efarkouh; 07-25-2016 at 10:56 AM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Find folder path for string in cell

    Try this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Re: Find folder path for string in cell

    I'm on my work computer and I'm having a hard time replying with quote (sorry about that).

    I tried to copy and paste that code outright and run it with the correct file path and I didn't get anything back in the cells.

    I have another version of the code using FSOs and it suffers from the same problem (won't go into folders within folders).

    Please Login or Register  to view this content.
    Can this be modified in any way to dig in deeper?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Find folder path for string in cell

    Are you trying to match a subfolder name or filename from column C?
    Can you give examples of what is in column C?

  5. #5
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Re: Find folder path for string in cell

    In column C is a list of (account) numbers, 3 digits, followed by a hyphen, followed by another 6 digits that would look like this:

    000-000000

    The folders I'm looking for would be named as follows:

    000-000000 - Account Name

    It would then be:

    "C:\Users\name\directory 1\directory 2\000-000000 - Account Name"

    I would like to look for the folder path containing the account number in column C and place that path in column D.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Find folder path for string in cell

    The code I suggested should work. Try changing this...

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Re: Find folder path for string in cell

    I get a run-time error (76): path not found.

    It points to this line when debugging:
    Please Login or Register  to view this content.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Find folder path for string in cell

    Did you change this to the actual path to start looking in; "C:\Users\name\directory 1\" ?

  9. #9
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Re: Find folder path for string in cell

    I did. I'm still trying to play around with it. The path is on a network drive.

  10. #10
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Re: Find folder path for string in cell

    It seems like it's working fine when it's not on the network drive. I'll try and figure it out.

    Thanks a lot!

  11. #11
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Find folder path for string in cell

    Quote Originally Posted by efarkouh View Post
    It seems like it's working fine when it's not on the network drive. I'll try and figure it out.

    Thanks a lot!
    The network drive does make a difference. You could map the network drive as a local letter drive and it should work.

  12. #12
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Re: Find folder path for string in cell

    I'll see if I can figure that out. Thanks again.

  13. #13
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Find folder path for string in cell

    I didn't test, but this should temporarily map a network drive as a drive letter.

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Re: Find folder path for string in cell

    It's already the U:\ drive. It won't let me access it via your solution but using my earlier code with FSO works fine. I'm still hacking away at it.

  15. #15
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Re: Find folder path for string in cell

    I just tried that temporary mapping and it gave me the same error as last time (76, path not found).

  16. #16
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Find folder path for string in cell

    Both are using FSO (FileSystemObject). I don't know why one works and not the other.

  17. #17
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Re: Find folder path for string in cell

    Quote Originally Posted by AlphaFrog View Post
    Both are using FSO (FileSystemObject). I don't know why one works and not the other.
    Any other suggestions? The dir method seems to be the faster of the two that I've tried. Is there any way to have that skim through subfolders?

  18. #18
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Find folder path for string in cell

    Dir doesn't readily do subfolders. There's probably some code out there that has a workaround to make it work, but I don't know of it.

    Why do you think Dir is faster? I've not experienced that.

    If you got the first FSO to work with the network drive path, there's probably a way to get the code I suggested to work as well since they both use the came FSO functions. What did you do to get your original FSO code to work; details? Show what you did in both cases.

  19. #19
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Re: Find folder path for string in cell

    Quote Originally Posted by AlphaFrog View Post
    Dir doesn't readily do subfolders. There's probably some code out there that has a workaround to make it work, but I don't know of it.

    Why do you think Dir is faster? I've not experienced that.

    If you got the first FSO to work with the network drive path, there's probably a way to get the code I suggested to work as well since they both use the came FSO functions. What did you do to get your original FSO code to work; details? Show what you did in both cases.
    When I specified an exact folder in order to test the macro, the Dir macro finished the process several seconds quicker than FSO (shown below and as in post #3 of this thread) macro. Bear in mind this test was done on the network drive.

    The exact code for the FSO method is (again) below and I can't really see why it would work, and your solution wouldn't. I used the exact same path that was in my code in yours and got an error. But when I tested yours on a test folder I made on the desktop, it worked beautifully.

    Please Login or Register  to view this content.

  20. #20
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Find folder path for string in cell

    Well I set up a network drive and used my code (only changing the network path) and it worked; It found specific subfolders. I don't know why it doesn't work for you. Maybe double-check your network path? Do you have permissions to access all subfolders in that path?

  21. #21
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Re: Find folder path for string in cell

    I'm back at work and I've tested your code by specifying the exact folder where to look (as I've done with my scripts) on the network drive and it worked fine so I think it's a bad folder on the network drive.

  22. #22
    Registered User
    Join Date
    08-20-2014
    Location
    Toronto, Canada
    MS-Off Ver
    2013
    Posts
    95

    Re: Find folder path for string in cell

    I added "On Error Resume Next" to the function and that fixed 'er right up.

    Please Login or Register  to view this content.
    Problem solved.

    Thanks again!

+ 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. [SOLVED] Help with Macro to find full path of Folder, using input of first 4 chars of folder name
    By Anxiety in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-28-2015, 09:02 AM
  2. Find latest modified folder and return path to cell
    By dave1983 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2014, 05:27 AM
  3. Code to list the folder path and sub folder path of a specific file
    By kalai1587 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2013, 03:51 AM
  4. Find folder path with partial information
    By superdonk in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-07-2013, 09:15 AM
  5. Find File with partial filename and get path of folder
    By axisambrosia in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-16-2012, 06:51 AM
  6. using cell contents as a string to define a folder path
    By RDS in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-13-2012, 04:16 PM

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