Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 15
Default Application.Filesearch yields incorrect results??

I use Application.Filesearch in an Excel macro to search through a series of
Word docs for a keyword. The search is initiated and the keyword(s) entered
via Userform. Hyperlinks to docs matching the search criteria are written
to a blank area on the worksheet.

The search works, except it just gave me some wrong answers. I entered
ABC-01. When I clicked the link and brought up the first doc, I did a Find
for ABC-01 - it was not found, but ABC-02 was!

Does the hyphen throw this off? Might other punctuations or non-alpha
characters? Any thoughts?

Ed

The Excel code:

Sub SearchKeyword()

Dim lngIndex As Long
Dim strSearchFor As String
Dim strLocation As String
Dim rngFiles As Range
Dim strName As String
Dim ListEnd As String

strLocation = ActiveWorkbook.Path

If Range("BA15000") < "" Then
ListEnd = Range("BA65536").End(xlUp).Row
Range("BA15000:BA" & ListEnd).ClearContents
End If

If UserForm2.TextBox2.Text < "" Then
strSearchFor = UserForm2.TextBox2.Text
End If
If UserForm2.TextBox3.Text < "" Then
strSearchFor = strSearchFor & " and " & UserForm2.TextBox3.Text
End If
If UserForm2.TextBox4.Text < "" Then
strSearchFor = strSearchFor & " and " & UserForm2.TextBox4.Text
End If
If UserForm2.TextBox5.Text < "" Then
strSearchFor = strSearchFor & " and " & UserForm2.TextBox5.Text
End If

If strSearchFor = "" Then
MsgBox "Nothing to search for", vbExclamation
Exit Sub
End If

strName = UserForm2.TextBox1.Text

With Application.FileSearch
.NewSearch
.LookIn = strLocation
.SearchSubFolders = False
.TextOrProperty = strSearchFor
.Filename = "L5-" & strName & "*.doc"
.Execute

ActiveSheet.Columns("BA").ColumnWidth = 80

Set rngFiles = Range("BA15000")
rngFiles.Offset(0, 0) = "Found " & .FoundFiles.Count & " containing
" & .TextOrProperty
For lngIndex = 1 To .FoundFiles.Count
ActiveSheet.Hyperlinks.Add Anchor:=rngFiles.Offset(lngIndex, 0),
Address:=.FoundFiles.Item(lngIndex)
Next
End With

Unload UserForm2

Range("BA15000").Select

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 27,285
Default Application.Filesearch yields incorrect results??

one argument to filesearch is

.MatchTextExactly = True

from help: True if the specified file search will find only files whose body
text or file properties contain the exact word or phrase that you've
specified.

doesn't say what the default setting is.

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
I use Application.Filesearch in an Excel macro to search through a series

of
Word docs for a keyword. The search is initiated and the keyword(s)

entered
via Userform. Hyperlinks to docs matching the search criteria are written
to a blank area on the worksheet.

The search works, except it just gave me some wrong answers. I entered
ABC-01. When I clicked the link and brought up the first doc, I did a

Find
for ABC-01 - it was not found, but ABC-02 was!

Does the hyphen throw this off? Might other punctuations or non-alpha
characters? Any thoughts?

Ed

The Excel code:

Sub SearchKeyword()

Dim lngIndex As Long
Dim strSearchFor As String
Dim strLocation As String
Dim rngFiles As Range
Dim strName As String
Dim ListEnd As String

strLocation = ActiveWorkbook.Path

If Range("BA15000") < "" Then
ListEnd = Range("BA65536").End(xlUp).Row
Range("BA15000:BA" & ListEnd).ClearContents
End If

If UserForm2.TextBox2.Text < "" Then
strSearchFor = UserForm2.TextBox2.Text
End If
If UserForm2.TextBox3.Text < "" Then
strSearchFor = strSearchFor & " and " & UserForm2.TextBox3.Text
End If
If UserForm2.TextBox4.Text < "" Then
strSearchFor = strSearchFor & " and " & UserForm2.TextBox4.Text
End If
If UserForm2.TextBox5.Text < "" Then
strSearchFor = strSearchFor & " and " & UserForm2.TextBox5.Text
End If

If strSearchFor = "" Then
MsgBox "Nothing to search for", vbExclamation
Exit Sub
End If

strName = UserForm2.TextBox1.Text

With Application.FileSearch
.NewSearch
.LookIn = strLocation
.SearchSubFolders = False
.TextOrProperty = strSearchFor
.Filename = "L5-" & strName & "*.doc"
.Execute

ActiveSheet.Columns("BA").ColumnWidth = 80

Set rngFiles = Range("BA15000")
rngFiles.Offset(0, 0) = "Found " & .FoundFiles.Count & "

containing
" & .TextOrProperty
For lngIndex = 1 To .FoundFiles.Count
ActiveSheet.Hyperlinks.Add Anchor:=rngFiles.Offset(lngIndex,

0),
Address:=.FoundFiles.Item(lngIndex)
Next
End With

Unload UserForm2

Range("BA15000").Select

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 15
Default Application.Filesearch yields incorrect results??

Good thought, Tom - but I added that in there and it didn't help. Clicked
the second link, did a Ctrl+F for "ABC-01", just as entered into the
Userform, and no good. "ABC" was in the doc, though. Maybe this is just a
limitation to live with and work around.

Ed

"Tom Ogilvy" wrote in message
...
one argument to filesearch is

.MatchTextExactly = True

from help: True if the specified file search will find only files whose

body
text or file properties contain the exact word or phrase that you've
specified.

doesn't say what the default setting is.

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
I use Application.Filesearch in an Excel macro to search through a

series
of
Word docs for a keyword. The search is initiated and the keyword(s)

entered
via Userform. Hyperlinks to docs matching the search criteria are

written
to a blank area on the worksheet.

The search works, except it just gave me some wrong answers. I entered
ABC-01. When I clicked the link and brought up the first doc, I did a

Find
for ABC-01 - it was not found, but ABC-02 was!

Does the hyphen throw this off? Might other punctuations or non-alpha
characters? Any thoughts?

Ed

The Excel code:

Sub SearchKeyword()

Dim lngIndex As Long
Dim strSearchFor As String
Dim strLocation As String
Dim rngFiles As Range
Dim strName As String
Dim ListEnd As String

strLocation = ActiveWorkbook.Path

If Range("BA15000") < "" Then
ListEnd = Range("BA65536").End(xlUp).Row
Range("BA15000:BA" & ListEnd).ClearContents
End If

If UserForm2.TextBox2.Text < "" Then
strSearchFor = UserForm2.TextBox2.Text
End If
If UserForm2.TextBox3.Text < "" Then
strSearchFor = strSearchFor & " and " & UserForm2.TextBox3.Text
End If
If UserForm2.TextBox4.Text < "" Then
strSearchFor = strSearchFor & " and " & UserForm2.TextBox4.Text
End If
If UserForm2.TextBox5.Text < "" Then
strSearchFor = strSearchFor & " and " & UserForm2.TextBox5.Text
End If

If strSearchFor = "" Then
MsgBox "Nothing to search for", vbExclamation
Exit Sub
End If

strName = UserForm2.TextBox1.Text

With Application.FileSearch
.NewSearch
.LookIn = strLocation
.SearchSubFolders = False
.TextOrProperty = strSearchFor
.Filename = "L5-" & strName & "*.doc"
.Execute

ActiveSheet.Columns("BA").ColumnWidth = 80

Set rngFiles = Range("BA15000")
rngFiles.Offset(0, 0) = "Found " & .FoundFiles.Count & "

containing
" & .TextOrProperty
For lngIndex = 1 To .FoundFiles.Count
ActiveSheet.Hyperlinks.Add Anchor:=rngFiles.Offset(lngIndex,

0),
Address:=.FoundFiles.Item(lngIndex)
Next
End With

Unload UserForm2

Range("BA15000").Select

End Sub






Reply
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
Application.FileSearch Cleberton(Brazilian) Excel Discussion (Misc queries) 2 October 26th 09 01:21 PM
Month function yields incorrect solution alwein Excel Worksheet Functions 4 December 16th 08 01:34 AM
ACCRINT formula yields incorrect result Onurali_k Excel Worksheet Functions 7 March 24th 05 05:47 PM
VBA Application.FileSearch Roger Frye Excel Programming 0 March 5th 04 04:07 AM
FileSearch macro returning incorrect docs? Ed[_9_] Excel Programming 2 December 10th 03 05:48 PM


All times are GMT +1. The time now is 08:46 AM.

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"