Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Parsing the file name

I need to parse the file name (e.g. MyFileName.xls) from a text string
containing the full path and file name. Surely there is an easy way to do
this. Please help me out!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Parsing the file name

Public Sub parse_filename()
'Alternatively you could use this command to get JUST the filename:
' FilName= Application.ActiveWorkbook.Name 'This returns "Myxlbook.XLS"

Filname = Application.ActiveWorkbook.FullName 'This returns "C:\Documents
and Settings\User\Myxlbook.XLS

For I = Len(Filname) To 1 Step -1
If Mid(Filname, I, 1) = "\" Then
Filname = Right(Application.ActiveWorkbook.FullName, Len(Filname) - I)
Exit For
End If
Next
Debug.Print Filname

End Sub

"Mitch" wrote in message
...
I need to parse the file name (e.g. MyFileName.xls) from a text string
containing the full path and file name. Surely there is an easy way to do
this. Please help me out!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Parsing the file name

Using some basic text manipulation functions it is not too bad to do.

Sub test()
MsgBox GetFileName("C:\Test\Test\this.xls")
End Sub

Public Function GetFileName(ByVal FullPath) As String
GetFileName = Right(FullPath, Len(FullPath) - InStrRev(FullPath, "\"))
End Function

--
HTH...

Jim Thomlinson


"Mitch" wrote:

I need to parse the file name (e.g. MyFileName.xls) from a text string
containing the full path and file name. Surely there is an easy way to do
this. Please help me out!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Parsing the file name

This is one way:

Public Function FileFromPath(ByVal strFullPath As String, _
Optional bExtensionOff As Boolean = False)
As String

Dim FPL As Long 'len of full path
Dim PLS As Long 'position of last slash
Dim pd As Long 'position of dot before exension
Dim strFile As String

On Error GoTo ERROROUT

FPL = Len(strFullPath)
PLS = InStrRev(strFullPath, "\", , vbBinaryCompare)
strFile = Right$(strFullPath, FPL - PLS)

If bExtensionOff = False Then
FileFromPath = strFile
Else
pd = InStr(1, strFile, ".", vbBinaryCompare)
FileFromPath = Left$(strFile, pd - 1)
End If

Exit Function
ERROROUT:

On Error GoTo 0
FileFromPath = ""

End Function


RBS


"Mitch" wrote in message
...
I need to parse the file name (e.g. MyFileName.xls) from a text string
containing the full path and file name. Surely there is an easy way to do
this. Please help me out!


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Parsing the file name

Mitch wrote:
I need to parse the file name (e.g. MyFileName.xls) from a text string
containing the full path and file name. Surely there is an easy way
to do this. Please help me out!


Another way:

sFileName = Dir(sPath)

as long as the file actually exists.

--
Dick Kusleika
MS MVP - Excel
www.dailydoseofexcel.com




  #6   Report Post  
Posted to microsoft.public.excel.programming
RaY RaY is offline
external usenet poster
 
Posts: 164
Default Parsing the file name

Sorry I found this post already exists with an answer..

Helps if you spell correctly when doing a search!


--
Ray


"Dick Kusleika" wrote:

Mitch wrote:
I need to parse the file name (e.g. MyFileName.xls) from a text string
containing the full path and file name. Surely there is an easy way
to do this. Please help me out!


Another way:

sFileName = Dir(sPath)

as long as the file actually exists.

--
Dick Kusleika
MS MVP - Excel
www.dailydoseofexcel.com



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
Import & Parsing a small 400 line CSV file tarns[_8_] Excel Programming 3 March 13th 06 02:38 AM
Parsing a Text File [email protected] Excel Programming 8 January 30th 06 04:43 PM
Issue with parsing text file into worksheet primrose Excel Programming 1 May 25th 05 05:09 PM
Parsing a space delimited file into segments robinsgate Excel Discussion (Misc queries) 6 March 18th 05 09:51 PM
Parsing imported text file with macro... help! scrupul0us[_2_] Excel Programming 0 September 7th 04 10:13 PM


All times are GMT +1. The time now is 11:57 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"