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
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