PDA

View Full Version : Shift clicking files storing filenames in an array



mattreingold
06-27-2018, 11:44 AM
Hello all, happy to be posting again.

I've got a rather simple question today, yet searching online has yielded no results.

What I would like is to be able to prompt a user to select files by shift clicking them, and storing each of the file names (including extensions) into a string array (which I could then open each, operate on it, close it, open next etc.).

Everything online grabs all files in a folder, I simply want to grab the names of the selected ones (by shift clicking) and store only those into an array.

I would post code, yet I had no idea where to even begin...

Thanks in advance guys!

Paul_Hossler
06-27-2018, 07:02 PM
You can start with this




Option Explicit

Sub GetListOfFiles()

Dim aFiles As Variant
Dim i As Long

aFiles = Application.GetOpenFilename("Excel Files (*.xls?), *.xls?)", 1, "List Files", "Select", True)

For i = LBound(aFiles) To UBound(aFiles)
MsgBox aFiles(i)
Next I

End Sub

mattreingold
06-28-2018, 07:48 AM
Wow, Paul. This couldn't work more perfectly... Thank you so so much.