Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FileSearch Object, Execute method (Office 2k win 2k)

    Hello All

    I'm trying to use the filesearch object to find me an Excel spreadsheet, so I started with the example in help, here is what I have so far: -

    Dim fs As Variant

    Set fs = Application.FileSearch
    With fs
    .LookIn = "My Computer"
    .FileName = "rejectpo.xls"
    If .Execute(SortBy:=msosortbyfilename, SortOrder:=msosortorder) > 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


    End Sub

    Thing is, it falls over because the msosortbyfilename isn't a declared variable, reading the help I didn't think it had to be.

    So, does it mean I'm missing a reference in my VBA editor, if so what? I can't see anything obvious. Or, do I actually need to declare these as variables? If so why? I thought they were standard methods for the filesearch object.

    Alternately, what silly little item have I missed?

    btw, I know the code wont do much for me that's productive at the minute, but I'll get around to productive when I sort out the methods etc.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileSearch Object, Execute method (Office 2k win 2k)

    In the Visual Basic Editor, select Tools | References...
    Set a reference to the Microsoft Office 9.0 Object Library, then click OK.
    Constants such as msoSortByFilename are part of the Office Object Library.

  3. #3
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileSearch Object, Execute method (Office 2k win 2k)

    Doh!!! I actually thought about adding that and decided that couldn't have anything to do with it.......

    Code now works as advertised.

    Thanks

    Ian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •