Re: Extract file name



Here is different version which also does not rely on a scripting object...

Function GetFileName(strFilePath)
GetFileName = Mid(strFilePath, InStrRev("\" & strFilePath, "\"))
End Function

Rick


"Rick Rothstein (MVP - VB)" <rick.newsNO.SPAM@xxxxxxxxxxxxxxxxxx> wrote in message news:OtnSKaf%23IHA.3852@xxxxxxxxxxxxxxxxxxxxxxx
Here is a UDF which does not rely on a scripting object (meaning it should be a little bit faster)...

Function GetFileName(strFilePath)
GetFileName = Split(strFilePath, "\")(UBound(Split(strFilePath, "\")))
End Function

Rick


"Dana DeLouis" <ddelouis@xxxxxxxxxxxxx> wrote in message news:4C27FC14-76EF-4B2D-82DD-76333473A906@xxxxxxxxxxxxxxxx
What function would extract the name: 84DTCC 2008_05

If you would like a UDF...

Function GetFileName(strFilePath)
GetFileName = CreateObject("Scripting.FileSystemObject").GetFileName(strFilePath)
End Function

Sub TestIt()
Dim s As String
s = "G:\CorporateAcct\SMR\Special\Support\84DTCC 2008_05.pdf"
Debug.Print GetFileName(s)
End Sub

Returns:
84DTCC 2008_05.pdf

--
HTH :>)
Dana DeLouis


"Steven" <Steven@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:00D65A82-8215-4A8C-9934-5A5C6DA93D0E@xxxxxxxxxxxxxxxx
What function would extact the name: 84DTCC 2008_05
out of this.
G:\CorporateAcct\SMR\Special\Support\84DTCC 2008_05.pdf

Note that the directory and subdirectory(ies) will not be constant (ie.
some may have more or less "\" )

Thank you,

Steven


.



Relevant Pages

  • Re: Macro Help Please
    ... You need to add the Scripting library to your project. ... completely (in which case, your macro won't work). ... > Dim DictFile As String ... > Dim Dict As Scripting.Dictionary ...
    (microsoft.public.word.vba.userforms)
  • Re: Formula?
    ... In a standard module paste: ... Function ReverseString(rng As Range) As String ... Dim i As Integer ... HTH ...
    (microsoft.public.excel.misc)
  • Re: initializing arrays
    ... Dim mtAs String ... HTH, ... Dave ...
    (microsoft.public.word.vba.general)
  • Re: Crystal Report Parameters - Date
    ... Dim d As String ... d is now a string displaying, eg, 4/28/04. ... >> HTH, ... >> Bernie Yaeger ...
    (microsoft.public.dotnet.languages.vb)
  • Re: new datefunction
    ... > Function SpDateAs String ... > Dim MYr As String ... > HTH ...
    (microsoft.public.excel.misc)