Skip to main content

How to extract the filename from a variable

Here is a way to extract the filename from a variable that contains the path and filename.

Sub Main

strFilePath = "C:\folder\folder\folder\file.txt"

MsgBox Mid(strFilePath, Len(strFilePath) - InStr(1, iReverse(strFilePath), "\") + 2, InStr(1, iReverse(strFilePath), "\") - 1)


End Sub