View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jonnie[_2_] Jonnie[_2_] is offline
external usenet poster
 
Posts: 1
Default List all files in a sub directory

On 5 Mar, 00:50, KateB wrote:
Hoping someone can help me - it seems that Application.FileSearch no
longer works in Excel 2007. I used to have a routine (below) which
listed all thefilesin adirectory(and possibly subdirectory. *I
had a dig around on the group last night & I think I need to use fso,
but I'm not exactly sure what that means, or how to implement it. *Can
someone help me?

My knowledge ofVBAis poor-moderate.

Thanks,
Kate

Sub ListFiles()
Set fs = Application.FileSearch

With fs
* * .LookIn = ActiveWorkbook.Path
* * .SearchSubFolders = True
* * .FileName = "*.*"
* * If .Execute() 0 Then
* * * * 'MsgBox "There were " & .FoundFiles.Count & _
* * * * ' " file(s) found."
* * * * 'For I = 1 To .FoundFiles.Count
* * * * ' * *MsgBox .FoundFiles(I)
* * * * 'Next I
* * Else
* * * * MsgBox "There were nofilesfound."
* * End If

* * 'write headings

* * Range("A1").Value = "Size (MB)"
* * Range("B1").Value = "File"
* * Range("C1").Value = "Date"

* * For i = 1 To .FoundFiles.Count

* * * * Range("B" & i + 1).Value = .FoundFiles(i)
* * * * Range("A" & i + 1).Value = FileLen(.FoundFiles(i)) / 1024 ^ 2
* * * * Range("C" & i + 1).Value = FileDateTime(.FoundFiles(i))

Next

End With

End Sub


Here is a simple program that I use to list files in a certain
directory!
http://vbaexcel.eu/vba-macro-code/li...s-in-directory