View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Paul Martin Paul Martin is offline
external usenet poster
 
Posts: 114
Default Ascertaining the directory name (2 levels up)

Hi all

I am using John Walkenbach's code to find the file name only from a
full path string. My structure is as follows:

PARENT_DIR
|
SUB_DIRECTORY
|
ThisWorkbook

I wish to ascertain the parent directory name. I have working code
(below) but am wondering if there's a simpler way to achieve this:
Dim sInitPath As String
Dim sNewPath As String
Dim sParentDir as string


sInitPath = CurDir
sNewPath = ThisWorkbook.Path & "\..\"

ChDrive sNewPath
ChDir sNewPath

sParentDir = FileNameOnly(CurDir)

ChDrive sInitPath
ChDir sInitPath

Thanks in advance

Paul Martin
Melbourne, Australia