Results 1 to 8 of 8
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using filesearch (PPT97, Word97)

    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??
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Using filesearch (PPT97, Word97)

    I think you're making it too hard on yourself by using the PropertyTests collection, although it should work. Try this:
    <pre>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</pre>

    HTH --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using filesearch (PPT97, Word97)

    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.
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  4. #4
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Using filesearch (PPT97, Word97)

    Jack, the PropertyTests collection causes <img src=/S/newbrain.gif border=0 alt=newbrain width=21 height=22>. 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?
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using filesearch (PPT97, Word97)

    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.
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  6. #6
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Using filesearch (PPT97, Word97)

    Glad you got answers and that you posted them here!

    <img src=/w3timages/blackline.gif width=33% height=2>
    > search masks can be concatenated using ";"
    <img src=/w3timages/blackline.gif width=33% height=2>

    Can you give an example?
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  7. #7
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using filesearch (PPT97, Word97)

    *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
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  8. #8
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Using filesearch (PPT97, Word97)

    Too Cool! <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15> Thanks! I knew that with, for example, *.bmp;*.jpg, but it never soaked in that a semi-colon is just an OR. <img src=/S/salute.gif border=0 alt=salute width=15 height=20> --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

Posting Permissions

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