applicationfilesearch
Microsoft Office TrainingThe UK's Number 1 for Microsoft Office Training add this page to your favourites/bookmarksBookmark page

view a printable version of this pagePrintable version
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Application.Filesearch

Application.Filesearch

The UK's most regular instructor-led training courses.
Training information: excel classes · Advanced.excel · Microsoft Excel Training UK
See also · excel-courses-london · excel courses in london · excel microsoft training

resolvedResolved · Urgent Priority · Version 2007

No ranking yet
1 post
replyReplyMon 25 Jan 2010, 15:46Delegate Jonathan said...

Jonathan has attended:
No courses

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

Excel Advanced 1 day course
Version Date Location Places
available
Book Next place rate (£)
Pay by
Card
Pay by
Invoice
2003 Wed 24 Mar 2010 Limehouse 7 Book now £212 £217
2007 Fri 26 Mar 2010 Rochester (Hoo) 0 FULL    
2007 Mon 29 Mar 2010 Bloomsbury 2 Book now £235 £240
2003 Wed 31 Mar 2010 Southwark 7 Book now £219 £224
2007 Tue 6 Apr 2010 Limehouse 5 Book now £235 £240
2007 Fri 9 Apr 2010 Southwark 8 Book now £193 £198
Full Schedule: See all 69 Excel Advanced course dates.
Bookings currently available until 22nd December 2010.

Platinum
755 posts
replyReplyWed 27 Jan 2010, 14:03 Edited on Wed 27 Jan 2010, 14:04Trainer Stephen said...

RE: Application.Filesearch

Hi Jonathon

Thanks 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.


Related articles

· Easing the Transition to Excel 2007
· Improve Performance Of Your Excel Macros
· Let Excel look after the pennies, and the pounds will take care of themselves
· Mastering Page Layout In Excel
· Tips From Excel's 'Rarely Used' File

Please browse our web site to find out more about
excel classes and other Microsoft training courses.

Excel tip:

Use the Format Painter to copy formatting more than once in Excel

The format painter tool provides a quick and easy way to copy formatting from one cell to another in Word.

The only problem is that if you click the Format Painter once to turn it on, you can only click and drag over a single cell or adjacent range of cells; then the Format Painter turns itself off automatically.

If you want to copy formatting to cells or groups of cells that are not adjacent to each other, double-click the Format Painter - this way you will be able to copy formatting to multiple cells.

When you have finished using Format Painter, press the Esc key or click on the Format Painter button once to turn it off.

View all Excel hints and tips


Rate this page:
2.1/5 (108 votes cast)
Institute of IT Training - Accredited Training Provider ILM
Microsoft Certified Partner
Microsoft Office Specialist Authorised Testing Centre (MOS and MCAS)

Prodigy Platinum Learning Partner

Institute of IT Training - Accredited Training Provider
McAfee Secure sites help keep you safe from identity theft, credit card fraud, spyware, spam, viruses and online scams
Association of Computer Trainers verified by visa, mastercard securecard