Extract A File Name From A Full Path
This code demonstrates a function that will extract the file name at the end of a full path.
Program Code
Option Explicit Public Sub TestFileNameExtract() Dim strFileName As String strFileName = ExtractFileNameFromPath("C:\MyDocuments\Rich\Morning.jpg") End Sub Public Function ExtractFileNameFromPath(FullPath As String) As String Dim i As Integer Dim length As Integer Dim temp As String Dim Cnt As Integer Dim txtSplitArray As Variant Cnt = 0 For i = 1 To Len(FullPath) If Mid(FullPath, i, 1) = Application.PathSeparator Then Cnt = Cnt + 1 End If Next i ' *********************************************************************** ' The Split Function Creates An Array in a Variant ' The Cnt Refers To The Last Array Entry, Which Is The Filename ' *********************************************************************** ExtractFileNameFromPath = Split(FullPath, Application.PathSeparator)(Cnt) End Function