View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
michdenis michdenis is offline
external usenet poster
 
Posts: 135
Default Another FileSearch Problem

Hi Ali,

In fact, this is the combinaison of these two lines that will give you the resultat you want !
I know, it's not obvious, but it's working !

..Filename = strLocFile & "*.*"
..FileType = msoFileTypeExcelWorkbooks


Salutations!





"Ali Campbell" a écrit dans le message de
...
Hi Michdenis -

I had already tried .FileType, but left the extension at *.xls, so will try with *.*; I'm also not sure if the change of
order between .LookIn and .FileName is significant, so will try that as well.

I'm off to the client later to test, so will report back after that.

Thanks

Alison
--
Alison


"michdenis" wrote:

Hi Ali,

Try this,

'---------------------------
With Application.FileSearch
.NewSearch
.LookIn = strFolderName
.Filename = strLocFile & "*.*"
.FileType = msoFileTypeExcelWorkbooks
.Execute
y = .FoundFiles.Count
End With
'---------------------------


Salutations!


"Ali Campbell" a écrit dans le message de
...
I didn't know whether to include this with my other post, because it came up in the same program, but is really a
different issue.

When I use the following code in Excel 97 (regardless of operating system) (to determine whether a file with no
extension - strLocFile - from one folder has a matching file with an .xls extension in another and, if so, count it):

With Application.FileSearch
.NewSearch
.FileName = strLocFile & ".xls"
.LookIn = strFolderName
.MatchTextExactly = True 'This doesn't work as required
.Execute
y = .FoundFiles.Count
End With

where strLocFile is a numeric file name (eg 1234), the procedure will consider the file 12345.xls to be a match, even
though I've used .MatchTextExactly.

I wrote the following workaround, which is placed immediately before the End With:

'This replaces MatchTextExactly property
' by testing for exact string match
If y 0 Then
For i = 1 To y
If LCase(Trim(strLocFile & ".xls")) = _
ParentFolder(LCase(Trim(.FoundFiles(1)))) Then
z = z + 1
Exit For
End If
Next i
End If

(ParentFolder is a function I wrote to get the last folder or file in a path; I'm now aware of another, simpler method
of getting the file name only, but haven't had a chance to test/apply it yet.)

Am I misinterpreting the use of .MatchTextExactly, or is it a bug? Does anyone have a tidier workaround?

BTW, does anyone else have a problem with the scroll bar to the right of the message window when posting these

messages?
Neither the arrow keys nor the grey scroll bar areas work (on this PC, at least) as they do in a normal windows

program,
so I can only use the scroll button or the keyboard arrows; however, I haven't posted in this forum before, so perhaps
it will be OK on my own PC!

Thanks and regards
--
Alison