loop through files in a folder

L

L Mehl

Hello --

I have some code to apply to each Word file in a folder.

Can someone outline for me or suggest resources to illustrate how to loop
through all the files in a folder ?
Given that, I can imbed the code in the loop.

Thanks for any help.

Larry Mehl
 
K

Khai

Dim fso
Dim i As Integer
Set fso = Application.FileSearch
With fso
.LookIn = "c:\temp\"
.SearchSubFolders = False
.FileName = "*"
.FileType = msoFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName,
SortOrder:=msoSortOrderDescending) > 0 Then
For i = 1 To .FoundFiles.Count
lstDir.AddItem Right(.FoundFiles(i), Len(.FoundFiles(i)) -
InStrRev(.FoundFiles(i), "\")) 'LstDir is a listbox in my document, this
adds the files in ReverseAlpha order to that list. You would probably store
it to an array.
Next i
End If
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top