XL FileSearch Object Operates Differently in XP

A

Alex J

All,

For a couple of years I have used the FileSearch object under XL2000
successfully. This was based on a slightly modified version of the
FileExists function in John Walkenbach's "XL2000 Power Programming with VBA"
as follows:





Function FileExists(fullpathname) As Boolean

' Returns TRUE if the file exists

' fullpathname represents the FULL Path of the file



FileExists = False

On Error GoTo Error1

With Application.FileSearch

.NewSearch

.FileName = fullpathname

.Execute

If .FoundFiles.Count = 0 Then

FileExists = False

Else

FileExists = True

End If

End With

Exit Function

Error1:



End Function





While testing migration to XP (XL2002), I found that the function was
providing unreliable results.



It seems that under XL2000, setting the [.Filename] to the full path name
coerced the [.Lookin] parameter of the FileSeach object to be the path
component of the [.FileName] parameter.



In XP, I found that the [.Lookin] parameter was not coerced, and so it
became necessary to define the [.Lookin] parameter explicitly in order for
the FileSearch object to be searching the correct directory.



Has this been documented anywhere? I found nothing specific in the XL2002
help files.



Are there any more of these little surprises lurking in the XL2002 object
model?



Regards,

Alex
 
T

Tom Ogilvy

It seems that under XL2000, setting the [.Filename] to the full path name
coerced the [.Lookin] parameter of the FileSeach object to be the path
component of the [.FileName] parameter.

I don't ever recall the above being documented anywhere, so no reason to
expect undocumented behavior to be preserved. Since the lookin parameter
is/has been provided, it would be reasonable to expect it to lookin the
location specified by the lookin parameter. I believe this is consistent
across versions.

--
Regards,
Tom Ogilvy



Alex J said:
All,

For a couple of years I have used the FileSearch object under XL2000
successfully. This was based on a slightly modified version of the
FileExists function in John Walkenbach's "XL2000 Power Programming with VBA"
as follows:





Function FileExists(fullpathname) As Boolean

' Returns TRUE if the file exists

' fullpathname represents the FULL Path of the file



FileExists = False

On Error GoTo Error1

With Application.FileSearch

.NewSearch

.FileName = fullpathname

.Execute

If .FoundFiles.Count = 0 Then

FileExists = False

Else

FileExists = True

End If

End With

Exit Function

Error1:



End Function





While testing migration to XP (XL2002), I found that the function was
providing unreliable results.



It seems that under XL2000, setting the [.Filename] to the full path name
coerced the [.Lookin] parameter of the FileSeach object to be the path
component of the [.FileName] parameter.



In XP, I found that the [.Lookin] parameter was not coerced, and so it
became necessary to define the [.Lookin] parameter explicitly in order for
the FileSearch object to be searching the correct directory.



Has this been documented anywhere? I found nothing specific in the XL2002
help files.



Are there any more of these little surprises lurking in the XL2002 object
model?



Regards,

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top