VBA Retrieve only the path from a file path


Example

The GetParentFolderName method returns the parent folder for any path. While this can also be used with folders, it is arguably more useful for extracting the path from an absolute file path:

Dim fso As New Scripting.FileSystemObject
Debug.Print fso.GetParentFolderName("C:\Users\Me\My Documents\SomeFile.txt")

Prints C:\Users\Me\My Documents

Note that the trailing path separator is not included in the returned string.