Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default extract filename from full path

Leung,
This works for me - it is a bit messy but I use the countmychar function
elsewhere.

HTH

Andi

Try :-
Sub Test
Dim workfilePath As String
Dim val_countPos as Integer
Dim Workfile as string
workfilePath = " F:\FC_bank\_common\Month-end Jun 05\MEJun2005\SAP\RC
code 13Jul2005.xls"
val_countpos = CountMyChar(workfilePath, 1, "B", "\") + 1
workfile = Mid(workfilePath, val_countpos) 'extract filename from
WorkfilePath
msgbox (workfile)
End Sub

Function CountMyChar(strCSV As String, ItemNo As Integer, FrontOrBack As
String, _
MySeparator As String) As String
'Function counts position of character within string - can count from front
or back
Dim i As Long
Dim OneItem As String
Dim n As Integer
Dim Var_CharCount As Integer
Dim Var_NumCharCount As Integer 'n'th item to find position of

Var_CharCount = 0 'current count of Item is 0

If UCase(FrontOrBack) = "F" Then
MySt = 1
MyFin = Len(strCSV)
MyStep = 1
Else
MySt = Len(strCSV)
MyFin = 1
MyStep = -1
End If

For n = MySt To MyFin Step MyStep
char = Mid(strCSV, n, 1)

If char = MySeparator Then
Var_NumCharCount = Var_NumCharCount + 1
End If

If Var_NumCharCount = ItemNo Then
Exit For
End If

Next n

CountMyChar = n

End Function



"Leung" wrote in message
...
Hi

Is there anyway use some text extract function in VBA so that I can

retrieve
the file name from these path? How to write a code in a function to

retrieve
the name:

such as intri function??
path:
F:\FC_bank\_common\Month-end Jun 05\MEJun2005\SAP\RC code 13Jul2005.xls
string to retrieve:
RC code 13Jul2005.xls

thanks

Leung





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
Full path-name in title bar ? Stefan Excel Discussion (Misc queries) 14 January 13th 10 11:00 AM
Full path possible to be seen? Octavio New Users to Excel 10 July 2nd 06 08:51 PM
Extract full path given filename Kim J. Excel Programming 3 October 14th 04 04:38 AM
Trim path from full filename Arawn Excel Programming 3 June 3rd 04 07:10 PM


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