Consulting

Results 1 to 11 of 11

Thread: Solved: Next level folder

  1. #1
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

    Solved: Next level folder

    Hi All.
    Activedocument.path returns the path to my document which is in a sub, sub folder. I want to get the sub folder, which is one level above. Can this be done without a string manipulation?
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    I suppose the simplest way to do it would be changing the current directory then assigning that to a variable[VBA]ChDir ActiveDocument.Path
    ChDir ".."
    myPath = CurDir[/VBA]
    K :-)

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Killian,
    I knew there were dots in the solution somewhere, and having now RTFH I tried:
    [VBA]
    Sub NextLevel()
    Debug.Print ActiveDocument.Path
    ChDir ActiveDocument.Path
    ChDir ".."
    mypath = CurDir
    Debug.Print mypath
    End Sub
    [/VBA]

    and got
    [VBA]M:\1174 PKC_Partnering_Kitchens\MergeLetters
    Z:\
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hi Malcolm,

    In your example, you're setting the current directory on the M drive.. IF the M drive is the current one. You have to add a ChDrive in there as well:[vba]Sub NextLevel()
    Dim mypath As String
    mypath = ActiveDocument.Path
    Debug.Print mypath
    ChDir mypath
    ChDrive mypath
    ChDir ".."
    mypath = CurDir
    Debug.Print mypath
    End Sub[/vba]Matt

  5. #5
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Is there a particular reason for not wanting to do string manipulation? (other than curiosity)
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  6. #6
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Theres also always[vba] Dim fso As Object
    Set fso = CreateObject("scripting.filesystemobject")
    MsgBox fso.GetParentFolderName(ActiveDocument.Path)
    Set fso = Nothing[/vba]Just as another alternative

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I knew there was a .. method of dealing with levels and thought it would be simpler! Not so it seems. I still don't understand where the Z: drive comes from though. It's on my system for my User area of the server, but I rarely if ever use it.
    Regards
    Malcolm
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Quote Originally Posted by mdmackillop
    I knew there was a .. method of dealing with levels and thought it would be simpler! Not so it seems. I still don't understand where the Z: drive comes from though. It's on my system for my User area of the server, but I rarely if ever use it.
    Regards
    Malcolm
    Is it your MyDocuments folder, or does word use it as the default file path? My V drive does the same thing, as it is setup as the system's My Documents folder

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Matt,
    Word is set to look for and save documents within the M drive. It's where all our "Contract" files are saved on the server
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I'd like to hear the answer to Tony's question. What is wrong with string manipulation? It is straightforward, and does not require the use of a reference to FileSystemObject. Not that is a real problem, but....I am curious as well.

  11. #11
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Gerry,
    There is nothing "wrong" with string maniplulation, but I know how to do that. I was simply looking for other simply employed methods of which I was not aware.
    Regards
    Malcolm
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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