Results 1 to 5 of 5

Reading in files from directory......does this code also alphabetize the file names

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Reading in files from directory......does this code also alphabetize the file names

    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
    Last edited by welchs101; 05-04-2012 at 07:29 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1