• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

File Path to remove [SOLVED]

webmax

Member
Hi,

I have the file path name C:UserswebmaxlDocumentsDelhi.xls


By using the formula i want only the file name which is Delhi without path and extension name.


kindly solve the above in excel formula as well as in using vba macro code.
 
I'd suggest using the method described here:

http://chandoo.org/wp/2012/10/23/extract-file-name-from-full-path-using-formulas/


The article shows how to find file name and extension. From there, you can do a

=SUBSTITUTE(FileName,Extension,"")

to get just the basic name w/o extension.

One VBA method:

[pre]
Code:
Sub LastBit()
Dim textBits As Variant
Dim myPath As String
Dim fName As String
Dim shortName As String
myPath = "C:UserswebmaxlDocumentsDelhi.xls"

textBits = Split(myPath, "")
fName = textBits(UBound(textBits))
shortName = Left(fName, (InStrRev(fName, ".", -1, vbTextCompare) - 1))
MsgBox "File name is: " & shortName

End Sub
[/pre]
 
If output from formula, put formula in A2.

If output from VBA, add this line:

Code:
Range("A2").value = shortName
 
Instead of Msgbox give the cell address:

[pre]
Code:
mypath = "C:UserswebmaxlDocumentsDelhis.xls"
myFile = Mid(mypath, InStrRev(mypath, "") + 1, InStrRev(mypath, ".") - InStrRev(mypath, "") - 1)
Range("A2").Value = myFile
[/pre]
 
Back
Top