FORMULA to display parent folder name

ms500716

New Member
Joined
May 6, 2004
Messages
47
Does anyone have ideas for a FORMULA (not a macro) that can be used to diplay the parent folder name in a cell? I don't need the file name or workbook name, just the folder name.

Example,
My Workbook is stored in the following location: C:\Files\ExcelFiles

I want a fromula to return "ExcelFiles", since that is the parent folder

I have searched previous threads but found no resoultion.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
try this:
Code:
=MID(A17,FIND("|",SUBSTITUTE(A17,"\","|",2))+1,FIND("[",A17)-1-FIND("|",SUBSTITUTE(A17,"\","|",2))-1)

but I think this will only work when the path is two layers deep
 
Upvote 0
I'm not sure what part of this isn't working, but it isn't. I get a #Value error.

BTW, my acutal path is 7 layers deep

\\folder1\folder2\folder3\folder4\folder5\folder6\folder7\filename.xls
 
Upvote 0
oops - for testing I had the filename in cell a17
so if you put into a cell the formula
=cell("filename")
does it show 7 "\"?

Code:
=MID(CELL("Filename"),FIND("|",SUBSTITUTE(CELL("filename"),"\","|",2))+1,FIND("[",CELL("filename"))-1-FIND("|",SUBSTITUTE(CELL("Filename"),"\","|",2))-1)
 
Upvote 0
Maybe use a UDF

Put this in a sub attached to the sheet:
Code:
Function FileFolder()
FileFolder = ActiveWorkbook.Path
End Function

Then in the workbook put:

=filefolder()
 
Upvote 0
The reason I want to use a formula is because the users accessing the file have high macro security that can't be changed.

I found a formula online, but it has an error in it somewhere. Can anyone tell where the error is?

=MID(CELL("filename"),FIND(CHAR(1),SUBSTITUTE(CELL("filename"),
"\", CHAR(1), LEN(CELL("filename")) - LEN(SUBSTITUTE(CELL("filename"),
"\", "")) - 1)) + 1, FIND("[", CELL("filename")) – 2 - FIND(CHAR(1),
SUBSTITUTE(CELL("filename"), "\", CHAR(1), LEN(CELL("filename")) -
LEN(SUBSTITUTE(CELL("filename"), "\", "")) - 1)))
 
Upvote 0
Code:
=MID(CELL("filename"),FIND(CHAR(1),SUBSTITUTE(CELL("filename"),
"\", CHAR(1), LEN(CELL("filename")) - LEN(SUBSTITUTE(CELL("filename"),
"\", "")) - 1)) + 1, FIND("[", CELL("filename"))-2 - FIND(CHAR(1),
SUBSTITUTE(CELL("filename"), "\", CHAR(1), LEN(CELL("filename")) -
LEN(SUBSTITUTE(CELL("filename"), "\", "")) - 1)))

the -2 needing to be fixed
 
Upvote 0
Sorry didn't see the part about the last dir only, Try this:

=TRIM(RIGHT(SUBSTITUTE(LEFT(CELL("filename"),FIND("[",CELL("filename"),1)-2),"\",REPT(" ",100)),100))

It works by getting the DIR and replacing all "\" with 100 spaces. It then grabs the right 100 chars which will be a bunch of spaces and the final DIR name then it trims off the preceding spaces.
 
Upvote 0
You should always reference CELL("FILENAME") with a cell reference from the workbook in question, otherwise you could inadvertently return the value from a different workbook that was worked on.

=CELL("FILENAME",A1)


To see this create two blank workbooks and save both of them
In cell A1 of each workbook, put =CELL("filename")
Then change something in the second workbook, go back to the first sheet, you will see that it no longer references the current workbook but the last one that changed.
 
Upvote 0

Forum statistics

Threads
1,216,725
Messages
6,132,347
Members
449,719
Latest member
excel4mac

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top