Forum home » Delegate support and help forum » Microsoft Excel Training and help » Application.Filesearch
Application.Filesearch
Resolved · Urgent Priority · Version 2007
Application.Filesearch
Hi there,I had written a macro in Excel 2003 which searches a directory and lists all of the files in that directory, of type *.ssn and writes this list to a worksheet. To do this i used the Application.Filesearch functionality. Having upgraded to Excel 2007 this no longer works and it would appear the Filesearch functionality has been removed. The code i used is below - could you suggest how i can get this working in Excel 2007 please. Note I no longer need it to be able to work in Excel 2003.
Regards,
Jonathan
Sub ListAllFiles()
Dim fs As FileSearch
Dim ws As Worksheet
Dim i As Long
Set fs = Application.FileSearch
'Clear the current File List
Sheets("MISC").Range("AL49:AL128").ClearContents
'Create a new File List - all *.ssn files in the strDataLocation data directory
With fs
.SearchSubFolders = False ' set to true if you want sub-folders included
'.FileType = msoFileTypeAllFiles 'can modify to just Excel files eg with msoFileTypeExcelWorkbooks
.Filename = "*.ssn" 'Can use wildcards for file types.
.LookIn = strDataLocation 'modify this to where you want to serach
If .Execute > 0 Then
Set ws = Worksheets("MISC")
For i = 1 To .FoundFiles.Count
ws.Cells(i + 48, 38) = Mid$(.FoundFiles(i), InStrRev(.FoundFiles(i), "\") + 1)
Next
Else
MsgBox "No files found"
End If
End With
End Sub
For upcoming training course dates see: Pricing & availability
RE: Application.Filesearch
Hi JonathonThanks for your question
The removal of the filesearch method in 2007 is annoying, and puzzling.
It is possible to use the Dir method, which is very old dating back to pre windows versions of basic. It is hard to give a precise example of how to use this as I would need to know more about your file structures etc. But I suggest some sort of loop , using the Dir method, that looks at each file in turn and then writes it to the sheet if its extension matches your category.
I have found the following link that outlines some uses of the dir method, which you might find useful.
http://www.ozgrid.com/forum/showpost.php?p=369573&postcount=4
If you have any further queries please do not hesitate to get back to me.
Regards
Stephen
Tue 2 Feb 2010: Automatically marked as resolved.
|
|
» Forum post: Formulas |
How To Save And View Multiple Baselines In Microsoft Project Baselines can be an invaluable tools within your Project plan, but Microsoft will normally only show your first baseline on the Gantt chart. Find out in this article how to display additional baselines and interim plans, and really enhance your Gantt charts » Article: Ms project training course |



Course updates

