I'm trying to use a file dialog to allow users to select the spreadsheet they want to import, but when I use the following code, I only get the folder path - the file name is left off.
What am I missing? I assume it's something very simple - I just haven't figure it out yet...
Code:
Private Function GetFileName() as String
Dim dlg As FileDialog
Set dlg = Application.FileDialog(msoFileDialogFilePicker)
With dlg
.Title = "Select the file you want to import:"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Microsoft Excel", "*.xls;*.xlsb;*.xlsm;*.xlsx", 1
.Filters.Add "All Files", "*.*", 2
If .Show = True Then
GetFileName = .InitialFileName
Else
GoTo FUNCTION_EXIT
End If
End With
FUNCTION_EXIT:
Exit Function
What am I missing? I assume it's something very simple - I just haven't figure it out yet...