PDA

View Full Version : Application.Filesearch incomplete



Kunz Berlin
06-17-2007, 12:49 PM
Hallo,
the results of Application.FileSearch are not complete. Who can help?


My program shall find all documents, that contain a certain keyword. It opens them one after another and copies all lines with that keyword (Selection.Find) into a new document. It searches in 8 folders with approx. 130 subfolders with altogether over 200 word-docs.

Closer description:
- not all docs, that contain the keyword, are found
- the incorrect result is exactly reproducible
- if you take the doc, that has incorrectly not been found, and type the keyword in a new line, it is found by the next search; but by using copy and paste, it is again not found.
- if by the new line the doc is found and then opened, Selection.Find finds both the old line and the new line.
- using a different keyword, which is also contained in the formerly not found doc, the doc is found.
- using the explorer-search > files and folders > text in the document the find list is complete

So it seems, as if on special lines there would lie a certain ?shadow?, by which some lines can not be recognized by Application.FileSearch. This ?shadow? remains by copy and paste.

(...)
With Application.FileSearch
.NewSearch
.LookIn = Searchpath(Modulgroup, 0)
.FileName = "*.doc"
.FileType = msoFileTypeAllFiles
.SearchSubFolders = True
.TextOrProperty = "*" + Searchtext(search) + "*"
End With

NumberFiles = Application.FileSearch.Execute()

If NumberFiles > 0 Then
For i = 1 To NumberFiles
DocFullName = Application.FileSearch.FoundFiles(i)
(...)
Next i
End If
(...)


For any kind of solution one to two million times THANKS in advance!

Greetings,
Kunz from Berlin, Germany

fumei
06-18-2007, 12:53 AM
Could you post either your complere code, or a file containing your code?

I have found that FileSearch does have some oddities that make it not 100% reliable...IMO. Although I have never heard of this copy/paste shadowing.

Could you explain your use of Selection.Find? You are opening them and using Selection.Find?

Kunz Berlin
06-18-2007, 02:40 AM
Hallo fumei,
the complete code is really bulky, so it would surely blast the thread.
The program gets a certain keyword by the user. Then it searches all documents in all (or in by user chosen) folders (Application.FileSearch, see above). Going through the list of results, each doc is opened one after another. In the opened doc the keyword is searched again. The lines with hits are copied, the section and page numbers are added and then pasted into a new ?result-doc?.

Documents.Open FileName:=DocFullName, ReadOnly:=True
ActiveDocument.Repaginate
ActiveDocument.Select

(?)

With Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = False
.MatchCase = False
.MatchWildcards = False
.Wrap = wdFindStop
.Text = Searchtext

Do While .Execute() = True

(?) <here: copy all hits of the doc one after another, condition each and output into ?result-doc?>

Loop
End With



You say you have heard about those problems before? Are there some statements from MS? Do you have a certain idea about the root of the problem and how to solve or dodge it?

Kunz from Berlin, Germany

fumei
06-18-2007, 08:44 AM
Maybe the code is bulky, but can you zipo a file and post it. It would be much better if we can actually see what is happening step-by-step.

For example are you clearing the FileSearch Lookin, before using it? This is one area where I have found FileSearch to be a little off sometimes.

fumei
06-18-2007, 08:48 AM
Oh, and your code above?

1. Please use the VBA tags to put code in a code window.

2. I am niot sure hiow you thought the code above would help. It tells us nothing really.

3. Why are you opening a document, then immediately calling an explicit Repaginate instruction? Unless you have told Word otherwise, when you open a document, it IS paginated.

fumei
06-18-2007, 08:55 AM
OK. I just did a test of 23 files across 4 subfolders, and I am having no problems with getting the appropriate files.

If possible, I really think you should post a file containing your code.

Kunz Berlin
06-19-2007, 10:09 PM
Hallo Gerry,
more than 99% is found correctly, so the finding routine should work, I guess. But why are there parts of a doc, which are not found unless it is opened?

Do you think the actual failure is right in the doc that shall be found?

I?m hardly searching an example-file. All those I recently had have been ?repaired? meanwhile. As soon as I found one, I?ll send it.

Kunz from Berlin, Germany