Hi,
I have a folder for each of 80 employees. The folder name is made up of the employees name and employee number e.g. Aldea, Robert 34
In each folder are timesheet files for that employee. Basically I need the code to find the correct employee folder and list the files in it. I have seen lots of posts about searching for files but can't find out how to search for a folder. Here is my code:
Here is what I get in the immediate window:
I don't know if I should be doing a special search for a folder of if its just a problem with string comparisons. Any ideas?
I have a folder for each of 80 employees. The folder name is made up of the employees name and employee number e.g. Aldea, Robert 34
In each folder are timesheet files for that employee. Basically I need the code to find the correct employee folder and list the files in it. I have seen lots of posts about searching for files but can't find out how to search for a folder. Here is my code:
Code:
strTestFolder = "C:\Monthly Employees\Aldea, Robert 34\" [COLOR="green"]'this works[/COLOR]
strBaseFolder = "C:\Monthly Employees\"
empNum = 34
[COLOR="Red"]empFolder = strBaseFolder & "*" & empNum & "\"[/COLOR]
Debug.Print "test: " & strTestFolder
Debug.Print "empl: " & empFolder
With Application.FileSearch
.NewSearch
[COLOR="Green"]' .LookIn = strTestFolder 'this works - prints out the files in the folder[/COLOR]
.LookIn = empFolder [COLOR="Green"]'this doesn't work[/COLOR]
.Filename = "*.*"
If .Execute > 0 Then [COLOR="Green"]'if the file searched for exists[/COLOR]
folderTimesheets = .FoundFiles(1)
Debug.Print folderTimesheets
End If
End With
Here is what I get in the immediate window:
Code:
test: C:\Monthly Employees\Aldea, Robert 34\
empl: C:\Monthly Employees\*34\
I don't know if I should be doing a special search for a folder of if its just a problem with string comparisons. Any ideas?