LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Filesearch finding the same file twice?

Got an interesting problem.

I've written a macro which will go to a directory of your choice and look
for excel files matching a certain name criteria. It will then open each file
found and copy out data from that file to the main file, in this way creating
a summary file. The found file is then closed.

Sometimes (and only sometimes), 1 file in the directory can be "found" twice
so that the data is copied twice. This can screw things up later down the
line when I average across a set of values from different parent files.
Interesting thing is that a lot of the time the filesearch works exactly as
it should.

Here is the filesearch code in question - the full macro is way too large to
post up.
----------------------------------------------
Set fs = Application.FileSearch

' Find all corresponding files in directory in question

With fs
.NewSearch
.LookIn = direc
.Filename = fil & "*.xls"
.SearchSubFolders = searchsub
.Execute

If .FoundFiles.Count = 0 Then
MsgBox "No files in directory"
GoTo endsub
Else
MsgBox "found " & .FoundFiles.Count & " files"
End If

End With
-----------------------------------------

Also, I assume there's an easy way to open the files, extract their data and
close them again all in the background but I don't know what it is, so at the
moment my excel screen flashes while up to 50 files can be opened, searched
and closed sequentially. Not the end of the world but a bit annoying
nonetheless.

Thanks for any light that can be shed here.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Alternative to FileSearch for Finding Directories [email protected] Excel Programming 7 July 11th 06 10:58 AM
Using .filesearch for text within a file Michael Wise[_32_] Excel Programming 1 April 10th 06 12:56 PM
Return most recent file in subdirectory with out using FileSearch Enohp Aikon Excel Programming 20 October 3rd 05 11:24 PM
FileSearch & .zip file keepITcool Excel Programming 0 April 14th 05 12:27 AM
filesearch not finding files Kevin Excel Programming 1 January 18th 05 01:49 PM


All times are GMT +1. The time now is 08:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"