By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,654 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Select from FileDialogfilepicker multiple selection and save in different variables

100+
P: 441
Here's my code
Expand|Select|Wrap|Line Numbers
  1. Set fd = Application.FileDialog(msoFileDialogFilePicker)
  2. fd.Filters.Add "All Pdf files", "*.pdf"
  3. fd.Filters.Add "All files", "*.*"
  4. fd.InitialFileName = "C:\attachements\"
  5. fd.InitialView = msoFileDialogViewList
  6. fd.AllowMultiSelect = True
  7. filechosen = fd.Show
  8.  If filechosen = -1 Then
  9.     For i = 1 To fd.SelectedItems.Count
  10.         Fname = fd.SelectedItems(i)
  11.     Next i
  12. End If
Because there are multiple selections I would like to save each on in a different variable. Is there a way to have Fname change to Fname with the i subscript added to the end. So the first selection would go into Fname1 and the next Fname2 etc.

Thanks for your help.
Nov 9 '18 #1

✓ answered by PhilOfWalton

Depends on what you want to do with the information.

One way is to create an array FNames()

Then your code becomes
Expand|Select|Wrap|Line Numbers
  1.     For i = 1 To fd.SelectedItems.Count
  2.         Redim Preserve FNames(1, i)
  3.         FNames(i) = fd.SelectedItems(i)
  4.     Next i
  5.  
Another way could be
Expand|Select|Wrap|Line Numbers
  1. FName & Chr$(i) = fd.SelectedItems(i)
  2.  
Then, as I said, what do you want to do with the file names?

Phil

Share this Question
Share on Google+
1 Reply


PhilOfWalton
Expert 100+
P: 1,430
Depends on what you want to do with the information.

One way is to create an array FNames()

Then your code becomes
Expand|Select|Wrap|Line Numbers
  1.     For i = 1 To fd.SelectedItems.Count
  2.         Redim Preserve FNames(1, i)
  3.         FNames(i) = fd.SelectedItems(i)
  4.     Next i
  5.  
Another way could be
Expand|Select|Wrap|Line Numbers
  1. FName & Chr$(i) = fd.SelectedItems(i)
  2.  
Then, as I said, what do you want to do with the file names?

Phil
Nov 10 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.