Parent Folder

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to return the parent folder relative to the folder for the current
workbook.

The following get me the path to my workbook such as
c:\test\subfolder1\subfolder2.

Function test()
Dim myString As String
myString = ThisWorkbook.Path
End Function

How can I modify the string to get
c:\test\subfolder1

Bruce
 
Hi Bruce,

For xl2k ==>>, try something like:

'===============>>
Public Sub Tester02()
Dim strPath As String
Dim strParent As String
Dim pos As Long

strPath = "c:\test\subfolder1\subfolder2"

pos = InStrRev(strPath, "\")

strParent = Left(strPath, pos - 1)

MsgBox strParent

End Sub

'<<===============
 
Depending on what you're doing, you could just use:

ThisWorkbook.Path & "\.."

to get to the parent directory.

(But this'll have trouble if you're in the root folder.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top