Log in

View Full Version : Sleeper: Application FileSearch help



geebra
12-28-2021, 11:57 AM
Hi,

I can't seem to get this converted correctly, any help is appreciated.


Dim fs
Dim i As Integer
Dim stlen As Integer
Set fs = Application.FileSearch
With fs
.LookIn = ActiveWorkbook.Path + "" + "Reports"
.filename = "*.rpt"
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending) > 0 Then
ComboBox1.Clear
stlen = Len(ActiveWorkbook.Path + "" + "Reports") + 1
For i = 1 To .FoundFiles.Count
ComboBox1.AddItem Mid(.FoundFiles(i), stlen)
Next i
ComboBox1.Value = Mid(.FoundFiles(1), stlen)
populate_archive
End If
End With

arnelgp
12-28-2021, 08:05 PM
something similar:



Private Sub Test()
Dim stPath As StringDim stFile As String
Dim stPattern As String
Dim aFiles() As String
Dim i As Integer
ReDim aFiles(500)
stPath = ActiveWorkbook.Path & "\Reports\"
stPattern = "*.rpt"
stFile = Dir$(stPath & stPattern)
Sheets(1).ComboBox1.Clear
If Len(stFile) <> 0 Then
Do Until Len(stFile) < 1
i = i + 1
aFiles(i - 1) = stFile
stFile = Dir$
Loop
ReDim Preserve aFiles(i - 1)
aFiles = ArrBubbleSort(aFiles)
For i = 0 To UBound(aFiles)
Sheets(1).ComboBox1.AddItem aFiles(i)
Next
End If
End Sub




Public Function ArrBubbleSort(arrVariant As Variant) As Variant
Dim lLoop1 As Long
Dim lLoop2 As Long
Dim lTemp As Variant
For lLoop1 = UBound(arrVariant) To LBound(arrVariant) Step -1
For lLoop2 = LBound(arrVariant) + 1 To lLoop1
If arrVariant(lLoop2 - 1) > arrVariant(lLoop2) Then
lTemp = arrVariant(lLoop2 - 1)
arrVariant(lLoop2 - 1) = arrVariant(lLoop2)
arrVariant(lLoop2) = lTemp
End If
Next lLoop2
Next lLoop1
ArrBubbleSort = arrVariant
End Function