Link to home
Start Free TrialLog in
Avatar of vbnetcoder
vbnetcoder

asked on

Browse button: get selected file name and file path

The attached code gets me the file path ... how would i isolate just the filename and get that too?

Private Sub cmdBrowse_Click()
Dim strFilePath As String
Dim strFileName As String

strFilePath = fSelectFileCSV()



MsgBox strFileName


   

End Sub


Function fSelectFileCSV()
Dim fd As Object
Set fd = Application.FileDialog(1)
With fd
    .Filters.Clear
    .Filters.Add "Text File", "*.csv"

    .AllowMultiSelect = False
    
    'initial path
    .InitialFileName = CurrentProject.Path ' change this to your desired default folder
    
    .Title = "Select File"
        
    If .Show = True Then
        fSelectFileCSV = .SelectedItems(1)
        
        
       
    End If
End With
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try
Res = Mid(fSelectFileCSV , InStrRev(fSelectFileCSV , "\") + 1)

Open in new window


Regards
dim strFileName as string, strFullPathAndFileName as string

strFullPathAndFileName=fSelectFileCSV()

if strFullPathAndFileName & ""<> "" then
    strFileName= mid(strFullPathAndFileName, instrrev(strFullPathAndFileName,"\")+1)

end if
Avatar of vbnetcoder

ASKER

ty