Lo creamos en un modulo:
Public Function GetFileName(flname As String) As String
'Get the filename without the path or extension.
'Input Values:
' flname - path and filename of file.
'Return Value:
' GetFileName - name of file without the extension.
Dim posn As Integer, i As Integer
Dim fName As String
posn = 0
'find the position of the last "\" character in filename
For i = 1 To Len(flname)
If (Mid(flname, i, 1) = "\") Then posn = i
Next i
'get filename without path
fName = Right(flname, Len(flname) - posn)
'get filename without extension
posn = InStr(fName, ".")
If posn <> 0 Then
fName = Left(fName, posn - 1)
End If
GetFileName = fName
End Function
Donde nosotros escribimos
C:\Documents and Settings\Luser\My Documents\ejemplo.txt
La función devuelve
ejemplo
La función se llama de la siguiente manera:
Dim FileName As String
FileName = GetFileName("C:\Documents and Settings\Luser\My Documents\ejemplo.txt")
No hay comentarios:
Publicar un comentario