I have the code below to populate a list box:
Now I want to be able to sort the two columns in the list box when the user click on a command button which I will place on top of the columns. Any help would be appreciated.
Private Sub UserForm_Activate()
Dim oFSO As Object, oFolder As Object, oFile As Object
Dim sPath As String
sPath = "C:2003\"
'Creates a system object so we can get access to Files and Folders
Set oFSO = CreateObject("Scripting.FileSystemObject"
'If a folder exixts in the specifed path (This might not be necessary)
If oFSO.FolderExists(sPath) Then
'Set the folder to the path we specifed
Set oFolder = oFSO.GetFolder(sPath)
'Initalize counter
C = 0
'Loop through for each file in the folder
For Each oFile In oFolder.Files
'Increment the counter
C = C + 1
'Only get the file name and the creation date for excel files
If LCase$(Right$(oFile.Name, 4)) = ".xls" Then
'Fill in the list box with the name of the file and the date
ListBox1.AddItem (oFile.Name)
ListBox1.List(C - 1, 1) = (oFile.DateLastModified)
End If
Next oFile
Set oFolder = Nothing
Else
MsgBox "Cannot find " & sPath
End If
End Sub
Now I want to be able to sort the two columns in the list box when the user click on a command button which I will place on top of the columns. Any help would be appreciated.
Private Sub UserForm_Activate()
Dim oFSO As Object, oFolder As Object, oFile As Object
Dim sPath As String
sPath = "C:2003\"
'Creates a system object so we can get access to Files and Folders
Set oFSO = CreateObject("Scripting.FileSystemObject"
'If a folder exixts in the specifed path (This might not be necessary)
If oFSO.FolderExists(sPath) Then
'Set the folder to the path we specifed
Set oFolder = oFSO.GetFolder(sPath)
'Initalize counter
C = 0
'Loop through for each file in the folder
For Each oFile In oFolder.Files
'Increment the counter
C = C + 1
'Only get the file name and the creation date for excel files
If LCase$(Right$(oFile.Name, 4)) = ".xls" Then
'Fill in the list box with the name of the file and the date
ListBox1.AddItem (oFile.Name)
ListBox1.List(C - 1, 1) = (oFile.DateLastModified)
End If
Next oFile
Set oFolder = Nothing
Else
MsgBox "Cannot find " & sPath
End If
End Sub