I have this little program to load the files from a directory into an array
and open them 10 at a time for editing. (got great help from mvp's to get
this far ;-)
But I would like to sort the array before opening the files so they come to
me alphabetically making it easier to deal with them after the editing
process.
I keep getting an 'out of subscript' error in the sort routine and suspect
that it has something to do with the ubound statement of the array, but
after trying several flavors of fix-up applied to the coding for the sort, I
am still getting the error and am stumped. Could you please tell me where to
put the statement in the sorting code? All help is much appreciated.
Here is the coding for the macro:
Sub GetFiles
Dim Resumes As String, FileArray() As String, Num As Long, OpnFile As Long
Dim PassNum As Integer, temp As String
Dim Upper As Long
ReDim FileArray(1200)
Num = 0
OpnFile = 0
''''''''''''' Load Array '''''''''''''''
Resumes = Dir$("C:\temp\*.txt")
Do While Len(Resumes) > 0
FileArray(Num) = Resumes
Num = Num + 1
Resumes = Dir$
Loop
ReDim Preserve FileArray(Num - 1)
Upper = UBound(FileArray)
'''''''''''' Sort array '''''''''''''''''
For PassNum = 0 To Num
For OpnFile = 1 To Num - PassNum
-- the following line is the one 'debug' points to as the problem --
If FileArray(OpnFile) < FileArray(OpnFile + 1) Then
Let temp = FileArray(OpnFile)
Let FileArray(OpnFile) = FileArray(OpnFile + 1)
Let FileArray(OpnFile + 1) = temp
End If
Next OpnFile
Next PassNum
''''''''''' Open files for editing '''''''''''''''
For OpnFile = 0 To 9
If OpnFile <= Upper Then
Documents.Open FileName:="C:\temp\" _
& FileArray(OpnFile)
Debug.Print OpnFile
End If
Next