Hi,
I found this code on the forum here.
What i cant tell is if the code also alphabetizes the file names in the array.
It looks like it does.......i have reviewed the code but i cant see where its doing it.....can someone confirm/help me on this one?
Private Sub get_list_of_files_and_path(file_array() As Variant, path1 As String, _
open_error As Boolean, Message_string As String)
Dim Cnt As Long
Dim ExcelFiles() As Variant
Dim FilePath As String
Dim FileName As String
Dim objShell As Object
open_error = False
Set objShell = CreateObject("Shell.Application")
Set oFolder = objShell.BrowseForFolder(0, Message_string, 0)
If oFolder Is Nothing Then
open_error = True
Exit Sub
End If
FilePath = oFolder.self.Path & "\"
'MsgBox (FilePath)
path1 = FilePath
'FileName = Dir(FilePath & "*.xls")
FileName = Dir(FilePath & "*.*")
If FileName = "" Then
MsgBox "No Excel Files were Found in this Folder.", vbCritical
open_error = True
Exit Sub
End If
Cnt = 1
Do While FileName <> ""
If Cnt = 1 Then
ReDim ExcelFiles(1 To Cnt)
ReDim file_array(1 To 2, 1 To Cnt)
Else
ReDim Preserve ExcelFiles(1 To Cnt)
ReDim Preserve file_array(1 To 2, 1 To Cnt)
End If
ExcelFiles(Cnt) = FilePath & FileName
file_array(1, Cnt) = FileName
'MsgBox (FileName)
Cnt = Cnt + 1
FileName = Dir()
Loop
End Sub
Bookmarks