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

Hi,
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?

Thanks

aTuL


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

I know you can get the name using\
ActiveWorkbook.name
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
Wend

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

End Sub

Ivan

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

Thanks Ivan and David. Really appreciate your help!