Reputation: 585
Every time I try to select only one file but I have .AlloMultiSelect = True There is an error message saying: Run-Time error '5':Invalid procedure call or argument and highlights "strPathAndSparks = .SelectedItems(2)". So my question is if I can enable multiselection and pick only one file, if so where is my mistake in this lines of code. This is what I have. I thank you all in advance.
strInitialDirectory = CurDir
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Title = "Choose Jira File"
.InitialFileName = CurDir & "\"
.AllowMultiSelect = True
.Filters.Clear
.Filters.Add "Excel Files", "*.xls;*.xlsx;*.xlsm"
If .Show = False Then
ChDir (strInitialDirectory)
Exit Sub
End If
strPathAndJira = .SelectedItems(1)
strPathAndSparks = .SelectedItems(2)
End With
Upvotes: 1
Views: 8088
Reputation: 53126
The error occurs if the user selects 1 or fewer items. You cannot compel the user to select 2 items, but you can test how many items were selected with
fd.SelectedItems.Count
Upvotes: 2