Trying to create an array of files that I can later 'cycle through' to pull information from each file (the files are laid out identically / forms in excel). Receiving '6' Overflow error, suspecting this is an error caused by my Loop?
Sub WorkOrderList()
'This compiles an array of Files by picking from the folder
Dim objFileDialog As Office.FileDialog
Dim SelectedFile As Variant
Dim arFiles() As Variant
Dim myCount As Integer
Set objFileDialog = Application.FileDialog(msoFileDialogFilePicker)
With objFileDialog
.AllowMultiSelect = True
.ButtonName = "Select"
.Title = "Work Order Picker"
If (.Show > 0) Then
End If
If (.SelectedItems.Count > 0) Then
For Each SelectedFile In .SelectedItems
Do Until SelectedFile = ""
myCount = myCount + 1
ReDim Preserve arFiles(1 To myCount)
arFiles(myCount) = SelectedFile
Loop
Next SelectedFile
Else
End If
End With
Set objFileDialog = Nothing
End Sub
I would expect a resulting array arFiles with each element of the array being the files selected from the msoFileDialogFilePicker.
ReDim arFiles(1 To .SelectedItems.Count)
just before you enter the loop. You know how many items you have, so you can avoid the repeated redim statements inside the loop. – Tim Williams Jan 28 '19 at 22:01SelectedFile
inside theDo Until SelectedFile = ""
loop. – Comintern Jan 28 '19 at 22:03