PDA

View Full Version : Application.FileSearch query



lynnnow
02-07-2008, 03:29 PM
Hi,

I've got this code:


Sub DocOpen()
Dim wdNew As Object
Dim File2Open As String

On Error Resume Next
Set wdNew = GetObject(, "Word.Application")
If wdNew Is Nothing Then
Set wdNew = CreateObject("Word.Application")
'wdNew.Visible = True
If wdNew Is Nothing Then
MsgBox "Error starting Word"
Exit Sub
End If
End If
'wdNew.Visible = True
With Application.FileSearch
.NewSearch
.LookIn = "D:\Lincoln\Today's Work\" & Format(ActiveCell.Offset(0, -1).Value, "mmmm dd")
.Filename = ActiveCell.Value & "-"
.FileType = msoFileTypeWordDocuments
.Execute
If .FoundFiles.Count <> 0 Then
wdNew.Visible = True
i = 1
Do While i <= .FoundFiles.Count
File2Open = .LookIn & "\" & .Filename & i '& ".doc"
On Error Resume Next
wdNew.documents.Open File2Open
i = i + 1
Loop
Else
MsgBox "No files of this name could be found", vbExclamation, "...::: Lynx's Corner :::..."
Set wdNew = Nothing
Exit Sub
End If
End With

Set wdNew = Nothing
' Call Error_Marker
End Sub


This works perfectly the way I want it. The problem is if I have the system's Indexing feature turned on, the FileSearch returns a 0 for items found. I turned off the Indexing feature and the macro returns the number of documents it has found.

What could be the possible reason for this?

Lincoln