I have a VBA script found on this site which ironically worked, and then it stopped...
I admittedly do not know how this works, as I can't barely parse out VBA, but the purpose of this is to find just the file name for a msofilepicker that runs. When I then value a cell to the variable fname, I get the entire filepicker name AND location.
Any assistance?
Thanks
I admittedly do not know how this works, as I can't barely parse out VBA, but the purpose of this is to find just the file name for a msofilepicker that runs. When I then value a cell to the variable fname, I get the entire filepicker name AND location.
Any assistance?
Thanks
VBA Code:
Sub ChooseFile()
Dim fd As FileDialog
Dim fName As String ' Includes full path
Dim fChosen As Integer
Dim fNameFile As String 'Only the name of the file
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Title = "Please select file"
fd.InitialFileName = "C:\Users\xx\Downloads\CSVdata*"
fChosen = fd.Show
fd.Filters.Clear
fd.Filters.Add "CSV files", "*.csv"
If fChosen <> -1 Then
MsgBox "You Cancelled, nothing done"
Else
fName = Right$(fd.SelectedItems(1), Len(fd.SelectedItems(1)) - InStrRev(fd.SelectedItems(1), "\"))
range("t5").value = fName
End If
End Sub
Last edited by a moderator: