Have found the code you are refering to and adapted it to my needs. The following is the source code as is:
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?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
thanks in advance
Florian




Reply With Quote