VBA: what?

29-01-2005

I have been working on a very simple VBA (VisualBasic for Applications) program. VisualBasic is pretty nasty in many ways, but it has improved somehow since it supports objects. And I am going to talk on one of this objects. Microsoft Office applications include an object to perform file searchs: FileSearch.

According to the documentation, the following code should do the thing (I just copied and pasted it from Microsoft web page):

Set fs = Application.FileSearch
With fs
    .LookIn = "C:\My Documents"
    .FileName = "whatever*.*"
    If .Execute > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
            " file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With

Well... it does not. There are 'whatever1', and 'whatever2' in the directory, but the is not able to locate anything.

But...

Set fs = Application.FileSearch
With fs
    .LookIn = "C:\My Documents"
    .FileName = "whatever"
    If .Execute > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
            " file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With

This works!! So now I believe that despite of what Microsoft documentation says, the FileSearch object does not support wilcards (and if it does, it is in a unsual way). It makes partial filename searchs though...

Very confusing...

I got a mail from a visitor of the page where he also had noticed this small issue. He was able to tell more on the source of the issue. Unfortunately, I crashed my mail and I lost that message. I am still searching for it. It was a very interesting message. (If he ever reads this, please tell me again).


comment feed - top


·La Rabadilla· ·Laconada· ·iRamos· ·O Vello Corvo· ·Palabros·
counter [CSS 2 Valid!] [XHTML 1.0 Valid!] [Made with Ant] [Get Firefox] RSS 1.0RSS 1.0 Atom 1.0RSS 1.0