Trim path from full filename

A

Arawn

I have a part of a macro that I need some help with.

I have the code that is returning the full file path, and then the
full file path with the filename, but I want to simply return the
filename for use in other coding.

Basically what I want is:

File_Name = (Full_Path_with_File_Name - Full Path)

However, I dont know how to go about this. Both the file name and
pathing will be variable, with varying lengths and names.

I'm using Excel 2003, if that makes a difference.

Thanks,

~Arawn
 
G

Guest

I'm sure there's some resevred word for getting just the file name
But in the meantime, here's another solution
Using the variable that captures the whole file path and file name, read it backwards a character at a time until the program finds the first slash ( \ ). Stop there, and you have your file name

Public sub Get_A_FileNam
File_Name = (Full_Path_with_File_Name - Full Path) ' assuming this actually gets the file path & name..
for a = len(File_Name) to 1 step -
if right(left(File_Name,a),1) = "\" the
msgbox("Your file name is " & right(File_Name,len(File_Name)-a)
exit fo
end i
next a
End Su

This code is untested, but feel free to try it out
Ti

----- Arawn wrote: ----

I have a part of a macro that I need some help with

I have the code that is returning the full file path, and then th
full file path with the filename, but I want to simply return th
filename for use in other coding

Basically what I want is

File_Name = (Full_Path_with_File_Name - Full Path

However, I dont know how to go about this. Both the file name an
pathing will be variable, with varying lengths and names

I'm using Excel 2003, if that makes a difference

Thanks

~Araw
 
M

michdenis

Hi Arawn,

2 functions :


'---------------
Function FileName(FullPath As String)
'Require Excel 2000 or more recent version
FileName = Split(FullPath, "\")(UBound(Split(FullPath, "\")))

End Function
'---------------

Function FileName1(FullPath As String)

FileName1 = Mid(FullPath, InStrRev(FullPath, "\") + 1)

End Function
'---------------

And to call one of these :

Msgbox FileName1("c:\path\MyWorkbook.xls")



Salutations!





"Arawn" <[email protected]> a écrit dans le message de I have a part of a macro that I need some help with.

I have the code that is returning the full file path, and then the
full file path with the filename, but I want to simply return the
filename for use in other coding.

Basically what I want is:

File_Name = (Full_Path_with_File_Name - Full Path)

However, I dont know how to go about this. Both the file name and
pathing will be variable, with varying lengths and names.

I'm using Excel 2003, if that makes a difference.

Thanks,

~Arawn
 
A

Arawn

Thanks Guys. I actually used a bit of both codes (ya never know when
stuff will work out extra conveniently like this!!)

It's working perfectly now.

Thanks again!

~Arawn
 

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

Top