MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Selecting the filenames only without giving the full path name

Posted by aTuL on July 31, 2000 1:37 AM

I'm using the GetOpenFileName Fucntion to open up another .xls file. When I use this way, it will return the full path name of the file. Is there any way that I can just extract the filename without the complete path?



Posted by david on July 31, 0100 3:59 AM

I know you can get the name using\
if it is the active workbook and it returns th short name

Posted by Ivan Moala on July 31, 0100 4:51 AM

Try something like this;

Sub TestFileName()
Dim FileNm
Dim Temp As String
Dim x As Integer

FileNm = Application.GetOpenFilename
If FileNm = "" Then End
x = 1
While InStr(x, FileNm, "\") <> 0
Temp = InStr(x, FileNm, "\")
x = x + 1

FileNm = Right(FileNm, Len(FileNm) - x + 1)

End Sub


Posted by aTuL on July 31, 0100 6:47 PM

Thanks Ivan and David. Really appreciate your help!