![]() |
Trim path from full filename
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 |
Trim path from full filename
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 |
Trim path from full filename
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" a écrit dans le message de om... 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 |
Trim path from full filename
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 |
All times are GMT +1. The time now is 10:53 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com