Consulting

Results 1 to 5 of 5

Thread: Macro: list of the 3 last subfolder of a file

  1. #1
    VBAX Newbie
    Joined
    Mar 2018
    Posts
    4
    Location

    Macro: list of the 3 last subfolder of a file

    Hi,
    I am looking for a macro that could extract the name of the last 3 parents folders from a file.
    Example: full path = c: \ document \ example \ ... \ ... \ folder1 \ folder2 \ folder3 \ myfile.docx
    I would like to get: folder1 folder2 folder3

    Thanks a lot by advance

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,053
    Location
    This thread looks a little familiar Rico. Have you posted this elsewhere?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    dim path as string
    dim var as variant
    dim i as integer
    dim j as integer
    dim sReturn as string
    path = "c: \ document \ example \ ...\ ...\folder1\folder2\folder3\myfile.docx"

    var= split(path, "\")
    for i = ubound(var)-1 to 0 step -1
    j = j + 1
    if j>3 then exit for
    sReturn = var(i) & " " & sReturn
    next
    'sReturn is the string you need
    sReturn = Trim$(sReturn)



  4. #4
    VBAX Newbie
    Joined
    Mar 2018
    Posts
    4
    Location
    Hi arnelgp,
    it's perfect , have a nice day

  5. #5
    Quote Originally Posted by Ricco View Post
    Hi arnelgp,
    it's perfect , have a nice day
    you're welcome!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •