I am able to select the file from filedialog function and storing the file path in string. but I also want the folder name of the selected path. Can you please advise as to how to get the folder path from select file.
File selected is :
U:\public\2016\Macro\CD-CW\109 file.xlsx
I want to show till :
U:\public\2016\Macro\CD-CW\
My Code
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
.Title = "Please select the file."
.Filters.Clear
.Filters.Add "Excel 2010", "*.xlsx"
.Filters.Add "All Files", "*.*"
If .Show = True Then
selfile = .SelectedItems(1) 'replace txtFileName with your textbox
End If
End With
This is very simple:
Dim filePath, directoryPath As String
filePath = "U:\public\2016\Macro\CD-CW\109 file.xlsx"
directoryPath = Left(filePath, InStrRev(filePath, "\"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With