• Using filesearch (PPT97, Word97)

    Author
    Topic
    #362707

    Not sure whether this is the right place to ask this question, but here goes:

    Trying to put a filesearch object into my PPT97 application. As a test, I am searching for all files with a “7” in the name. Using the Search from Windows Explorer, I can search for files like: *7*.* in a folder, and find several files.

    Yet when I repeat the search in the Advanced Search of FileOpen dialog from either Word or PPT, no files are returned. Similarly, the following code snippet returns no files:

    Set objSearch = Application.FileSearch
    With objSearch
    .NewSearch
    .PropertyTests.Add Name:=”Filename”, _
    Condition:=msoConditionIncludes, _
    Value:=”7″
    end with

    How can I make the filesearch object return the same file list as does Windows Explorer?

    Thx

    BTW — I find it ironic/typical/frustrating that the Help for FileSearch says that the Name property corresponds to the Value of the Property Box of the Advanced Search. However, the advanced search uses “file name”, while FileSearch object uses “filename”. Minor difference, but enough to cause a proram error. Dontcha just love MS consistency??

    Viewing 0 reply threads
    Author
    Replies
    • #551529

      I think you’re making it too hard on yourself by using the PropertyTests collection, although it should work. Try this:

      Option Explicit
      Sub Macro1()
      Dim objSearch As Office.FileSearch
      Dim i As Integer
          Set objSearch = Application.FileSearch
          With objSearch
              .NewSearch
              .LookIn = "D:My Documents"
              .SearchSubFolders = True
              .FileName = "*7*.doc"
              If .Execute(SortBy:=msoSortByLastModified) > 0 Then
                  For i = 1 To .FoundFiles.Count
                      MsgBox .FoundFiles(i)
                  Next i
              Else
                  MsgBox "No files found."
              End If
          End With
          Set objSearch = Nothing
      End Sub

      HTH –Sam

      • #551537

        Thanks Sam
        I was using this as a first step to searching the filename based on multiple terms connected with AND. Turns out that the FileName won’t support multiple search terms.

        • #551692

          Jack, the PropertyTests collection causes newbrain. It is still easier to do this with the .FileName property of the FileSearch object, using * and/or ? as wildcards. In either case there is just one PropertyTest for the filename, whose name must be “File name”. It appears to me that If you add more PropertyTests with different names, then the search fails and returns nothing, but I cannot find any documentation (I’m as shocked as you are!). Put a breakpoint at the .Execute and add a watch for objSearch.PropertyTest. Click on the plus signs and look at the PropertyTests to see what I mean.

          Back to the problem, what are the “multiple terms connected with AND” that you want to use?

          • #551891

            I’ve been playing both ends against the middle – posted the same question on a different tech support board, and got an answer there. (tek-tips.com)

            Here’s the situation — we accumulate a lot of digital images on our server, and people need easy access to them. The file names are coded with photographer, date, subject, and sequence number. For example:
            AJM-2001-001-skidder-steep-coast.jpg
            AJM-2001-002-cable-coast-flat.jpg

            I want to be able to find all the fields that are from me, on the coast and about skidders.

            The solution is to search for *AJM*skidder*coast*.jpg. This search mask finds one of the two files mentioned above.

            I was hoping to combine these terms into the PropertyTest collection using the AND operator, but have learned that’s not possible.

            The downside with the *word1*word2* method is that its “order-sensitive”. I may be able to live with that by always following alphabetic order. Alternatively, search masks can be concatenated using “;”, which may prove to be useful.

            Of course, all of this can be done with third-party image-management software. The beauty of my solution is that it’s all done with standard filenames and completely integrated into Word and Powerpoint using VBA.

            • #551959

              Glad you got answers and that you posted them here!


              > search masks can be concatenated using “;”

              Can you give an example?

            • #552217

              *ea*bs*.jpg;*home*.jpg (meaninless example)

              returns all jpg files that have “ea” followed by “bs” in their name OR files that have “home” in their name.

              so it combines AND and OR operators in a single line

              this works in Explorer File Find, as well as in the FileSearch object

            • #552253

              Too Cool! thumbup Thanks! I knew that with, for example, *.bmp;*.jpg, but it never soaked in that a semi-colon is just an OR. salute –Sam

    Viewing 0 reply threads
    Reply To: Using filesearch (PPT97, Word97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: