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.
 
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.

Good point Hotpepper:

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

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Thank you all for your help. The formula Blade Hunter gave works perfectly.

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

Thanks again!
 
Upvote 0
Don't complicate your life

this macro list all files in a folder and automatically adds an hyperlink to the folder and to the file itself (first define iRow = 1)

Yes, it also shows the folder name...

Sub ListFiles()


iRow = 11

Rows(iRow & ":" & "65536").Clear

'grab the path from a cell or else, this is just an example
Call ListMyFiles("C:\Program Files\Microsoft Office")



End Sub

Sub ListMyFiles(mySourcePath)
Set MyObject = CreateObject("Scripting.FileSystemObject")
Set mySource = MyObject.GetFolder(mySourcePath)
On Error Resume Next
For Each myFile In mySource.Files
iCol = 2
Cells(iRow, iCol).Value = myFile.path
iCol = iCol + 1

'this is the folder name with the hyperlink
Cells(iRow, iCol).Hyperlinks.Add _
Anchor:=Cells(iRow, iCol), _
Address:=mySourcePath, _
TextToDisplay:=mySource.Name
iCol = iCol + 1

'this is the file name with the hyperlink
Cells(iRow, iCol).Hyperlinks.Add _
Anchor:=Cells(iRow, iCol), _
Address:=myFile.path, _
TextToDisplay:=myFile.Name
iCol = iCol + 1

Cells(iRow, iCol).Value = myFile.Size / 1024 'for kilobytes display
iCol = iCol + 1

Cells(iRow, iCol).Value = myFile.DateLastModified

iRow = iRow + 1

Next

For Each mySubFolder In mySource.SubFolders
Call ListMyFiles(mySubFolder.path)
Next


End Sub
 
Upvote 0
That's not what the op was asking for, the op wanted to return the path of the workbook the formula was in. The op also specifically asked for a formula, not a macro. But you do know this thread is almost 8 years old right?
 
Last edited:
Upvote 0
That's not what the op was asking for, the op wanted to return the path of the workbook the formula was in. The op also specifically asked for a formula, not a macro. But you do know this thread is almost 8 years old right?

Sure, just thought it might be helpful
 
Upvote 0

Forum statistics

Threads
1,215,987
Messages
6,128,138
Members
449,426
Latest member
revK

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