Runtime error 445, need help

geebr200

New member
Joined
Mar 13, 2014
Messages
3
Reaction score
0
Points
0
Hi all,

I recently updated to Office 2010 and some of my previous macro are not working and I have received runtime error 445. I did some reaseach and realized that it no longer support the Application.Filesearch

Code:
Public Sub onstart()
Dim fs
Dim i As Integer
Dim stlen As Integer
Set fs = [B]Application.FileSearch
[/B]With fs
    .LookIn = ActiveWorkbook.Path
    .filename = "*.rpt"
    ComboBox1.Clear
    ComboBox1.Text = ""
    If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending) > 0 Then
        stlen = Len(ActiveWorkbook.Path) + 2
        For i = 1 To .FoundFiles.Count
            ComboBox1.AddItem Mid(.FoundFiles(i), stlen)
        Next i
        ComboBox1.Value = Mid(.FoundFiles(1), stlen)
        populate_archive
    Else
        ComboBox1.Value = NOFILES
    End If
End With
End Sub

Public Sub listbox_onstart()
Dim fs
Dim i As Integer
Dim stlen As Integer
Set fs = [B]Application.FileSearch
[/B]With fs
    .LookIn = ActiveWorkbook.Path
    .filename = "*.rpt"
    ListBox1.Clear
    If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending) > 0 Then
        stlen = Len(ActiveWorkbook.Path) + 2
        For i = 1 To .FoundFiles.Count
            ListBox1.AddItem Mid(.FoundFiles(i), stlen)
        Next i
    End If
End With
End Sub

Can you guys help me edit this to get it working again?

Thanks
 

Bob Phillips

Super Moderator
Staff member
Joined
Mar 21, 2011
Messages
1,942
Reaction score
0
Points
36
Excel Version(s)
O365
You could use Dir to get all the files in a directory of a certain type.
 

geebr200

New member
Joined
Mar 13, 2014
Messages
3
Reaction score
0
Points
0
Hi can you give an example? And I assume activeworkbook.path won't work anymore?

Thanks
 

Bob Phillips

Super Moderator
Staff member
Joined
Mar 21, 2011
Messages
1,942
Reaction score
0
Points
36
Excel Version(s)
O365
Something along the lines of

Code:
Dim filename As String

    filename = Dir(activeworkbookpath & Application.PathSeparator & "*.rpt")
    If filename <> "" Then
    
        'do someting with the name
        Do While filename <> ""
        
            filename = Dir
            If filename <> "" Then
    
                'do someting with the name
            End If
        Loop
    End If
 

geebr200

New member
Joined
Mar 13, 2014
Messages
3
Reaction score
0
Points
0
Something along the lines of

Code:
Dim filename As String

    filename = Dir(activeworkbookpath & Application.PathSeparator & "*.rpt")
    If filename <> "" Then
    
        'do someting with the name
        Do While filename <> ""
        
            filename = Dir
            If filename <> "" Then
    
                'do someting with the name
            End If
        Loop
    End If

I am still quite lost, sorry if this is really basic stuff.
 
Top