th1chsn
10-29-2007, 01:14 PM
Hello! I'm hoping that there are some people on this forum that might know how to help me. What I'm trying to do is look in a directory and get the filename of the first file, do some things to it, then get the next one, etc.
Here's the code I have. I get up to the point where the code knows how many files are in the directory. What I'm trying to do is declare s to equal the name of the first file. I thought s = .Filename would work but it doesn't.
Dim s as String
With Application.FileSearch
.NewSearch
.LookIn = "C:\User\Files"
.SearchSubFolders = False
.Filename = "*.xls"
If .Execute > 0 Then 'Only do this if there are files in the directory
For Count = 1 To .FoundFiles.Count ' Loop through all.
s = .Filename
Next Count
End If
End With
Does anyone know how to do this?
Here's the code I have. I get up to the point where the code knows how many files are in the directory. What I'm trying to do is declare s to equal the name of the first file. I thought s = .Filename would work but it doesn't.
Dim s as String
With Application.FileSearch
.NewSearch
.LookIn = "C:\User\Files"
.SearchSubFolders = False
.Filename = "*.xls"
If .Execute > 0 Then 'Only do this if there are files in the directory
For Count = 1 To .FoundFiles.Count ' Loop through all.
s = .Filename
Next Count
End If
End With
Does anyone know how to do this?