Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
http://CannotDeleteFile.net - Cannot Delete File? Try Long Path ToolFilename is too long? Computer Complaining Your Filename Is Too Long? TheLong Path Tool Can Help While most people can go about their businessblissfully unaware of the Windo | Excel Discussion (Misc queries) | |||
How do i display the Filename without the path? | Excel Discussion (Misc queries) | |||
Full path possible to be seen? | New Users to Excel | |||
Pulling in the path to a filename | Excel Worksheet Functions | |||
filename and path as constant | Excel Programming |