Results 1 to 19 of 19

Thread: Solved: Problem application.filesearch: find directory of file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Have found the code you are refering to and adapted it to my needs. The following is the source code as is:

     
    Private myList() As String
    Sub SearchFiles()
        myFileSearch _
        myDir:="D:", _
        FileNameLike:="file", _
        FileTypeLike:="xlsm", _
        SearchSubFol:=True, _
        myCounter:=0
     
        If Join(myList) = "" Then
            MsgBox "Could not find the requested file.", vbExclamation, "File Search Editor"
        Else
            MsgBox "Found the file at:" & vbLf & Join(myList, vbLf)
        End If
     
    End Sub
    Private Sub myFileSearch(myDir As String, FileNameLike As String, FileTypeLike As String, SearchSubFol As Boolean, myCounter As Long)
        Dim fso As Object, myFolder As Object, myFile As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
        For Each myFile In fso.GetFolder(myDir).Files
            If myFile.Name Like FileNameLike & "." & FileTypeLike Then
                myCounter = myCounter + 1
                ReDim Preserve myList(1 To myCounter)
                myList(myCounter) = myDir & "\" & myFile.Name
            End If
        Next
        If SearchSubFol Then
            For Each myFolder In fso.GetFolder(myDir).SubFolders
                myFileSearch myDir & "\" & myFolder.Name, FileNameLike, FileTypeLike, True, myCounter
            Next
        End If
    End Sub
    The error occurs on line: 'For Each myFile In fso.GetFolder(myDir).Files'. The error type is Runtime Error '70': Permission denied. Note that I am trying to search the entire drive D:\ for an excel file. Once I copy the excel-file into a folder and search within the folder (regardless of the number of subfolders), the code seems to work. Does this problem have to do with the admin settings? (I am logged on as adminsitrator with all read / write rights). Any ideas?
    thanks in advance
    Florian
    Last edited by fboehlandt; 09-16-2008 at 06:56 AM.

Posting Permissions

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