Results 1 to 5 of 5

Thread: Runtime error 445, need help

  1. #1

    Runtime error 445, need help



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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 = Application.FileSearch
    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 = Application.FileSearch
    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

  2. #2
    You could use Dir to get all the files in a directory of a certain type.

  3. #3
    Hi can you give an example? And I assume activeworkbook.path won't work anymore?

    Thanks

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

  5. #5
    Quote Originally Posted by Bob Phillips View Post
    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.

Posting Permissions

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