Getting Filename from full file path

  • I am running a custom function in VBA that returns a list of full path's of files in a folder, such as:


    I then add this list of paths to a listbox, but i want only the last part to appear in the listbox, i.e.


    Not that other information

    Is there any way to do this (Isuppose combining the right, mid and find functions)??????



  • Hi DW,

    DW is also my initials :)

    Here is function that do what You want:

    Function Filnamn(FileName As Variant)
    Dim lnNuvPos As Long, lnPos As Long

    lnNuvPos = 1
    Do While lnNuvPos <> 0
    lnPos = lnNuvPos + 1
    lnNuvPos = InStr(lnPos, FileName, "\")

    Filnamn = Mid$(FileName, lnPos, Len(FileName))

    End Function

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!