ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide file path on a text box (https://www.excelbanter.com/excel-programming/324600-hide-file-path-text-box.html)

Geto

Hide file path on a text box
 
How can I improve this code?... I want to select a file on the computer, show
the name in a textbox after selected, and then clicking a button to open it.

So far this is what I have, is not exactly what I want but it works...
what I want to fix right now, is to hide the entire path of the file to be
opened and only display the file name... how can I do that?

fileToOpen = Application.GetOpenFilename("Excel files (*.xls), *.xls")
If fileToOpen < False Then TextBox1.Text = fileToOpen



Mika

Hide file path on a text box
 
From J. Walkenbach:

Private Function FileNameOnly(pname) As String
' Returns the filename from a path/filename string
Dim i As Integer, length As Integer, temp As String
length = Len(pname)
temp = ""
For i = length To 1 Step -1
If Mid(pname, i, 1) = Application.PathSeparator Then
FileNameOnly = temp
Exit Function
End If
temp = Mid(pname, i, 1) & temp
Next i
FileNameOnly = pname
End Function

Rgds
Mika



All times are GMT +1. The time now is 12:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com