Thought I'd just put a quick reply to this as I was having trouble with this file searching process. I used it in Access and then tried to use it when writing an Outlook macro, with no joy. I think it is specific to Access, because I managed to change my code as follows and it now works. Know this post is old, but if anyone has the same problem as us, could save hours of frustration. (You need to add the 'Microsoft Access 9.0 Object Library' to your references).
Sub processFiles()
Dim app02 As New Access.Application Dim filename Dim NumFiles NumFiles = 0
line1: With Access.Application.FileSearch .NewSearch .LookIn = "C:\Temp\Dataprep\" .SearchSubFolders = False .MatchTextExactly = True .filename = "*.*" .Execute
End With
If FileSearch.FoundFiles.Count > 0 Then filename = FileSearch.FoundFiles.Item(1)
'Put your code that processes files here
Name filename As Left(filename, 17) & "processed\" & Mid(filename, 18, 60) NumFiles = NumFiles + 1 GoTo line1 Else
End If MsgBox NumFiles & " File(s) Processed!", vbOKOnly, "Finished!" End Sub
All this code does is loop through the dataprep folder and place all the files it finds in a 'processed' sub folder.
This is placed in an excel module and seems to do the trick. I know the code's probably badly written but hope it will be of use to someone.
|