Consulting

Results 1 to 2 of 2

Thread: Sleeper: Application FileSearch help

  1. #1
    VBAX Regular
    Joined
    Aug 2012
    Posts
    12
    Location

    Sleeper: Application FileSearch help

    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
    Last edited by Aussiebear; 12-28-2021 at 02:07 PM. Reason: Added code tags to supplied code

  2. #2
    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

Posting Permissions

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