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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
dim strFileName as string, strFullPathAndFileName as string
strFullPathAndFileName=fSe lectFileCS V()
if strFullPathAndFileName & ""<> "" then
strFileName= mid(strFullPathAndFileName , instrrev(strFullPathAndFil eName,"\") +1)
end if
strFullPathAndFileName=fSe
if strFullPathAndFileName & ""<> "" then
strFileName= mid(strFullPathAndFileName
end if
ASKER
ty
pls try
Open in new window
Regards