Я нашел код VBA ниже после поиска Google. Он сортирует массив по алфавиту и работает быстрее, чем Bubblesort. Однако я не могу понять, как изменить код для сортировки моего одномерного массива, который является списком файлов, по расширению файла? Это смесь файлов Word (.do c) и файлов Excel (.xlsx) в массиве. Я хотел бы отсортировать файлы так, чтобы все файлы Word сортировались перед файлами Excel. Чтобы уточнить массив после сортировки, можно выполнить следующий пример ...
(filename.doc)
(filename.doc)
(filename.doc)
(filename.doc)
(filename.doc)
(filename.xlsx)
(filename.xlsx)
(filename.xlsx)
(filename.xlsx)
Код ...
Sub Quicksort(vArray As Variant, arrLbound As Long, arrUbound As Long)
'Sorts a one-dimensional VBA array from smallest to largest
'using a very fast quicksort algorithm variant.
Dim pivotVal As Variant
Dim vSwap As Variant
Dim tmpLow As Long
Dim tmpHi As Long
tmpLow = arrLbound
tmpHi = arrUbound
pivotVal = vArray((arrLbound + arrUbound) \ 2)
While (tmpLow <= tmpHi) 'divide
While (vArray(tmpLow) < pivotVal And tmpLow < arrUbound)
tmpLow = tmpLow + 1
Wend
While (pivotVal < vArray(tmpHi) And tmpHi > arrLbound)
tmpHi = tmpHi - 1
Wend
If (tmpLow <= tmpHi) Then
vSwap = vArray(tmpLow)
vArray(tmpLow) = vArray(tmpHi)
vArray(tmpHi) = vSwap
tmpLow = tmpLow + 1
tmpHi = tmpHi - 1
End If
Wend
If (arrLbound < tmpHi) Then Quicksort vArray, arrLbound, tmpHi 'conquer
If (tmpLow < arrUbound) Then Quicksort vArray, tmpLow, arrUbound 'conquer
End Sub
Любая помощь будет принята с благодарностью.