+ Reply to Thread
Results 1 to 5 of 5

Parsing the file name

  1. #1
    Mitch
    Guest

    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. #2
    Jim Thomlinson
    Guest

    RE: 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!


  3. #3
    Newsgroup
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #4
    RB Smissaert
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    >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. #5
    Dick Kusleika
    Guest

    Re: 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.

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



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1