+ Reply to Thread
Results 1 to 4 of 4

Application.FileSearch on only one level of sub folders

  1. #1
    Crustysquirrel
    Guest

    Application.FileSearch on only one level of sub folders

    I want to use Application.FileSearch to search for xls files in the second
    level of a folder structure. I have many folders with the target xls files in
    each folder. But then an 'archive' folder attached to the folder with more
    xls files with the same name. Everytime it searches I end up with the main
    file and the archive file.

    Due to the number of folders, I need to use the .SearchSubFolders = True
    property, but is there any way of telling it to only go down one level?

    Level 1
    |__ Level 2...
    | |__ ****.xls - WANT TO SEARCH THESE
    | |__ Level 3...
    | |__ ****.xls - NOT THESE
    |__ Level 2...
    |__ Level 2...

    The extract of code I have is:

    With Application.FileSearch
    .NewSearch
    .LookIn = "c:\temp\amp test"
    .Filename = "933_????.xls"
    .SearchSubFolders = True
    .FileType = msoFileTypeExcelWorkbooks
    If .Execute() > 0 Then ......................blah blah blah

    Any help on this would be great, thanks.


  2. #2
    Tom Ogilvy
    Guest

    Re: Application.FileSearch on only one level of sub folders

    No, but you can easily put in an if statement when working with the results
    and only process those found at the second level.

    --
    Regards,
    Tom Ogilvy

    "Crustysquirrel" <[email protected]> wrote in message
    news:[email protected]...
    > I want to use Application.FileSearch to search for xls files in the second
    > level of a folder structure. I have many folders with the target xls files

    in
    > each folder. But then an 'archive' folder attached to the folder with more
    > xls files with the same name. Everytime it searches I end up with the main
    > file and the archive file.
    >
    > Due to the number of folders, I need to use the .SearchSubFolders = True
    > property, but is there any way of telling it to only go down one level?
    >
    > Level 1
    > |__ Level 2...
    > | |__ ****.xls - WANT TO SEARCH THESE
    > | |__ Level 3...
    > | |__ ****.xls - NOT THESE
    > |__ Level 2...
    > |__ Level 2...
    >
    > The extract of code I have is:
    >
    > With Application.FileSearch
    > .NewSearch
    > .LookIn = "c:\temp\amp test"
    > .Filename = "933_????.xls"
    > .SearchSubFolders = True
    > .FileType = msoFileTypeExcelWorkbooks
    > If .Execute() > 0 Then ......................blah blah blah
    >
    > Any help on this would be great, thanks.
    >




  3. #3
    Crustysquirrel
    Guest

    Re: Application.FileSearch on only one level of sub folders

    That is great, thanks for your help Tom. I will have to see how the IF is
    going to fit in with my code.

    "Tom Ogilvy" wrote:

    > No, but you can easily put in an if statement when working with the results
    > and only process those found at the second level.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "Crustysquirrel" <[email protected]> wrote in message
    > news:[email protected]...
    > > I want to use Application.FileSearch to search for xls files in the second
    > > level of a folder structure. I have many folders with the target xls files

    > in
    > > each folder. But then an 'archive' folder attached to the folder with more
    > > xls files with the same name. Everytime it searches I end up with the main
    > > file and the archive file.
    > >
    > > Due to the number of folders, I need to use the .SearchSubFolders = True
    > > property, but is there any way of telling it to only go down one level?
    > >
    > > Level 1
    > > |__ Level 2...
    > > | |__ ****.xls - WANT TO SEARCH THESE
    > > | |__ Level 3...
    > > | |__ ****.xls - NOT THESE
    > > |__ Level 2...
    > > |__ Level 2...
    > >
    > > The extract of code I have is:
    > >
    > > With Application.FileSearch
    > > .NewSearch
    > > .LookIn = "c:\temp\amp test"
    > > .Filename = "933_????.xls"
    > > .SearchSubFolders = True
    > > .FileType = msoFileTypeExcelWorkbooks
    > > If .Execute() > 0 Then ......................blah blah blah
    > >
    > > Any help on this would be great, thanks.
    > >

    >
    >
    >


  4. #4
    NickHK
    Guest

    Re: Application.FileSearch on only one level of sub folders

    Crusty,
    There is an earlier thread "Macro won't run from d: drive, but works on c:
    drive", from 29/07/05 that highlights the inadequanies of .FileSearch.
    A Dir() for all the directories, then Dir() each directory should be easy
    enough.

    NickHK

    "Crustysquirrel" <[email protected]> wrote in message
    news:[email protected]...
    > That is great, thanks for your help Tom. I will have to see how the IF is
    > going to fit in with my code.
    >
    > "Tom Ogilvy" wrote:
    >
    > > No, but you can easily put in an if statement when working with the

    results
    > > and only process those found at the second level.
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > > "Crustysquirrel" <[email protected]> wrote in

    message
    > > news:[email protected]...
    > > > I want to use Application.FileSearch to search for xls files in the

    second
    > > > level of a folder structure. I have many folders with the target xls

    files
    > > in
    > > > each folder. But then an 'archive' folder attached to the folder with

    more
    > > > xls files with the same name. Everytime it searches I end up with the

    main
    > > > file and the archive file.
    > > >
    > > > Due to the number of folders, I need to use the .SearchSubFolders =

    True
    > > > property, but is there any way of telling it to only go down one

    level?
    > > >
    > > > Level 1
    > > > |__ Level 2...
    > > > | |__ ****.xls - WANT TO SEARCH THESE
    > > > | |__ Level 3...
    > > > | |__ ****.xls - NOT THESE
    > > > |__ Level 2...
    > > > |__ Level 2...
    > > >
    > > > The extract of code I have is:
    > > >
    > > > With Application.FileSearch
    > > > .NewSearch
    > > > .LookIn = "c:\temp\amp test"
    > > > .Filename = "933_????.xls"
    > > > .SearchSubFolders = True
    > > > .FileType = msoFileTypeExcelWorkbooks
    > > > If .Execute() > 0 Then ......................blah blah blah
    > > >
    > > > Any help on this would be great, thanks.
    > > >

    > >
    > >
    > >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1