Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
TF TF is offline
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
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 Max Loger Excel Discussion (Misc queries) 0 June 14th 11 04:30 PM
How do i display the Filename without the path? robert_manic Excel Discussion (Misc queries) 3 October 11th 06 05:47 PM
Full path possible to be seen? Octavio New Users to Excel 10 July 2nd 06 08:51 PM
Pulling in the path to a filename Pradhan Excel Worksheet Functions 5 November 8th 05 02:36 AM
filename and path as constant mark kubicki Excel Programming 1 January 10th 04 09:38 PM


All times are GMT +1. The time now is 06:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"