Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    How to find parent folder of default location in Word

    Is it possible to get the parent folder of a default file location in Word?

    For example: sPath = Options.DefaultFilePath(wdStartupPath)

    Is it possible to use .Parent to get the folder above? Of course, I can parse sPath based on the \ character, but it seems there should be a more direct wa.

    Thanks.

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Richard,

    Apparently not:
    FindParent.JPG
    However, this should do the trick.
    VBAFindParent.JPG
    Code:
    Option Explicit
    
    Sub FindParent()
    
       Dim zPath     As String
       Dim zParent   As String
       Dim iCntr     As Integer
       
       zPath = Options.DefaultFilePath(wdStartupPath)
       For iCntr = Len(zPath) To 2 Step -1
          If Mid(zPath, iCntr, 1) = "\" Then
            zParent = Left(zPath, iCntr - 1)
            Exit For
          End If
       Next iCntr
       Debug.Print zPath & vbCrLf & zParent
      
    End Sub
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts
    Thanks. I used InStrRev to determine the position of the last \ with good results.

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Another way to do it, with reference set to Microsoft Scripting Runtime:
    Code:
       Dim FSO As New FileSystemObject
       Dim oFolder As Folder
       Dim sParentFolderName As String
       
       Set oFolder = FSO.GetFolder(Options.DefaultFilePath(wdStartupPath))
       sParentFolderName = FSO.GetParentFolderName(oFolder)
       Debug.Print sParentFolderName
       Set oFolder = Nothing
       Set FSO = Nothing
    Gary

  5. #5
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Ah, so many ways to skin the cat. But, pitty the poor cat he's stilled skinned!
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

Posting Permissions

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